IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Spring Java Discussion :

Hibernate mapper un fichier zippé (blob)? [Data]


Sujet :

Spring Java

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Janvier 2005
    Messages
    156
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 156
    Points : 57
    Points
    57
    Par défaut Hibernate mapper un fichier zippé (blob)?
    Salut,

    Comment faire pour mapper une colonne ds une table de type blob (oracle) avec une property ds une fichier java ?

    Merci

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Juillet 2006
    Messages
    548
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2006
    Messages : 548
    Points : 635
    Points
    635
    Par défaut
    Regarde du coté des UserType : tu peux implémenter ton propre type et le mapper une ou plusieurs colonnes

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Janvier 2005
    Messages
    156
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 156
    Points : 57
    Points
    57
    Par défaut
    Citation Envoyé par the-gtm
    Regarde du coté des UserType : tu peux implémenter ton propre type et le mapper une ou plusieurs colonnes
    Salut,

    Mais quand j'implemente le UserType, y a plein de fct à rédfinir dont je sais pas quoi mettre sauf le equals ?

    Tu aurais une idée ou un exemple ?
    Merci

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Juillet 2006
    Messages
    548
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2006
    Messages : 548
    Points : 635
    Points
    635
    Par défaut
    Une classe que j'avais faire pour mapper une java.awt.Color sur une colonne int :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    public class ColorType implements UserType {
        private static final int[] TYPES = new int[] {Types.INTEGER};
     
        @SuppressWarnings("unused")
        public Object assemble(Serializable cached, Object owner) throws HibernateException {
            return (Color) cached;
        }
     
        public Object deepCopy(Object value) throws HibernateException {
            return value;
        }
     
        public Serializable disassemble(Object value) throws HibernateException {
            return (Serializable) value;
        }
     
        public boolean equals(Object x, Object y) throws HibernateException {
            if (x == null) {
                return y == null;
            } else {
                return x.equals(y);
            }
        }
     
        public int hashCode(Object x) throws HibernateException {
            return x.hashCode();
        }
     
        public boolean isMutable() {
            return false;
        }
     
        @SuppressWarnings("unused")
        public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
            return new Color(rs.getInt(names[0]));
        }
     
        public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
            st.setInt(index, ((Color) value).getRGB());
        }
     
        @SuppressWarnings("unused")
        public Object replace(Object original, Object target, Object owner) throws HibernateException {
            return original;
        }
     
        public Class returnedClass() {
            return Color.class;
        }
     
        public int[] sqlTypes() {
            return TYPES;
        }
    }
    Mais sinon tout est expliqué dans la java doc de l'interface.

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Janvier 2005
    Messages
    156
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 156
    Points : 57
    Points
    57
    Par défaut
    Merci bcp.

    Citation Envoyé par the-gtm
    Une classe que j'avais faire pour mapper une java.awt.Color sur une colonne int :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    public class ColorType implements UserType {
        private static final int[] TYPES = new int[] {Types.INTEGER};
     
        @SuppressWarnings("unused")
        public Object assemble(Serializable cached, Object owner) throws HibernateException {
            return (Color) cached;
        }
     
        public Object deepCopy(Object value) throws HibernateException {
            return value;
        }
     
        public Serializable disassemble(Object value) throws HibernateException {
            return (Serializable) value;
        }
     
        public boolean equals(Object x, Object y) throws HibernateException {
            if (x == null) {
                return y == null;
            } else {
                return x.equals(y);
            }
        }
     
        public int hashCode(Object x) throws HibernateException {
            return x.hashCode();
        }
     
        public boolean isMutable() {
            return false;
        }
     
        @SuppressWarnings("unused")
        public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
            return new Color(rs.getInt(names[0]));
        }
     
        public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
            st.setInt(index, ((Color) value).getRGB());
        }
     
        @SuppressWarnings("unused")
        public Object replace(Object original, Object target, Object owner) throws HibernateException {
            return original;
        }
     
        public Class returnedClass() {
            return Color.class;
        }
     
        public int[] sqlTypes() {
            return TYPES;
        }
    }
    Mais sinon tout est expliqué dans la java doc de l'interface.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Hibernate] Mapper une table sans clé primaire
    Par neuromencien dans le forum Hibernate
    Réponses: 4
    Dernier message: 13/06/2006, 17h05
  2. Réponses: 3
    Dernier message: 08/06/2006, 17h38
  3. Mapper des fichiers
    Par bigbang dans le forum C++
    Réponses: 2
    Dernier message: 25/05/2006, 12h46
  4. [Hibernate] Mapper une classe association
    Par mauvais_karma dans le forum Hibernate
    Réponses: 16
    Dernier message: 25/01/2006, 12h34
  5. Réponses: 10
    Dernier message: 10/01/2006, 14h14

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo