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

Hibernate Java Discussion :

Hibernate + Oracle 10g (+ Maven)


Sujet :

Hibernate Java

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Juillet 2009
    Messages
    10
    Détails du profil
    Informations personnelles :
    Âge : 34
    Localisation : France

    Informations forums :
    Inscription : Juillet 2009
    Messages : 10
    Points : 11
    Points
    11
    Par défaut Hibernate + Oracle 10g (+ Maven)
    Bonjour,

    Pour faire simple, je vous expose déjà ma situation :

    J'ai une BDD (oracle 10g) avec une table et à partir de là j'ai généré l'entité associée avec les annotations (merci le plugin eclipse qui va bien). J'ai donc la classe suivante :


    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
    @Entity
    @Table(name = "USERS")
    public class Users implements java.io.Serializable {
     
    	private short id;
    	private String name;
    	private Short age;
     
    	public Users() {
    	}
     
    /* ... */
     
    	@Id
    	@Column(name = "ID", unique = true, nullable = false, precision = 4, scale = 0)
    	public short getId() {
    		return this.id;
    	}
     
    	public void setId(short id) {
    		this.id = id;
    	}
     
    	@Column(name = "NAME", nullable = false, length = 20)
    	public String getName() {
    		return this.name;
    	}
     
    /* ... */
     
    	@Column(name = "AGE", precision = 3, scale = 0)
    	public Short getAge() {
    		return this.age;
    	}
    /* ... */
    }
    Mon fichier hibernate.cgf.xml (qui a servit pour générer l'entité précédente, donc il doit être bon) :

    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
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
    <session-factory>
      <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
      <property name="hibernate.connection.url">jdbc:oracle:thin:@127.0.0.1:1521:bdd</property>
      <property name="hibernate.connection.username">florian</property>
      <property name="hibernate.connection.password">florian</property>
      <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
      <property name="hibernate.default_schema">FLORIAN</property>
      <property name="hibernate.temp.use_jdbc_metadata_defaults">false</property>
      <property name="show_sql">true</property>
     
      <mapping class="iso.domain.model.Users"></mapping>
     </session-factory>
    </hibernate-configuration>
    Et voici mon bout de test (présent dans une servlet) :

    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
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction transaction = null;
     
    try {
    	transaction = session.beginTransaction();
    	Users user = (Users) session.get(Users.class, 1);
    	System.out.println(user.getName());
    	//transaction.commit();
    } catch (HibernateException he) {
    	if (transaction != null) {
    		try {
    			transaction.rollback();
    		} catch (HibernateException he2) {
    			he2.printStackTrace();
    		}
    	}
    } finally {
    	if (session != null) {
    		try {
    			session.close();
    		} catch (HibernateException he) {
    			he.printStackTrace();
    		}
    	}
    }
    HibernateUtil est tirée de la doc hibernate, je le remet au cas où :

    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
    public class HibernateUtil {
    	private static SessionFactory sessionFactory;
     
    	@SuppressWarnings("deprecation")
    	private static SessionFactory buildSessionFactory() {
    		try {
    			sessionFactory= new Configuration().configure().buildSessionFactory();
    			return sessionFactory;
    		} catch (Throwable ex) {
    			System.err.println("Initial SessionFactory creation failed." + ex);
    			throw new ExceptionInInitializerError(ex);
    		}
    	}
     
     
    	public static SessionFactory getSessionFactory() {
    		if (sessionFactory==null) buildSessionFactory();
    		return sessionFactory;
    	}
    }
    Quand j'accède à ma servlet, j'ai dans la console :

    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
    Infos: Server startup in 296 ms
    avr. 25, 2012 9:55:31 PM org.hibernate.annotations.common.Version <clinit>
    INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
    avr. 25, 2012 9:55:31 PM org.hibernate.Version logVersion
    INFO: HHH000412: Hibernate Core {4.1.1}
    avr. 25, 2012 9:55:31 PM org.hibernate.cfg.Environment <clinit>
    INFO: HHH000206: hibernate.properties not found
    avr. 25, 2012 9:55:31 PM org.hibernate.cfg.Environment buildBytecodeProvider
    INFO: HHH000021: Bytecode provider name : javassist
    avr. 25, 2012 9:55:31 PM org.hibernate.cfg.Configuration configure
    INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
    avr. 25, 2012 9:55:31 PM org.hibernate.cfg.Configuration getConfigurationInputStream
    INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
    avr. 25, 2012 9:55:31 PM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
    WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
    avr. 25, 2012 9:55:31 PM org.hibernate.cfg.Configuration doConfigure
    INFO: HHH000041: Configured SessionFactory: null
    avr. 25, 2012 9:55:31 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
    avr. 25, 2012 9:55:31 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    INFO: HHH000115: Hibernate connection pool size: 20
    avr. 25, 2012 9:55:31 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    INFO: HHH000006: Autocommit mode: false
    avr. 25, 2012 9:55:31 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    INFO: HHH000401: using driver [oracle.jdbc.driver.OracleDriver] at URL [jdbc:oracle:thin:@127.0.0.1:1521:utbm]
    avr. 25, 2012 9:55:31 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    INFO: HHH000046: Connection properties: {user=florian, password=****}
    avr. 25, 2012 9:55:31 PM org.hibernate.dialect.Dialect <init>
    INFO: HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect
    avr. 25, 2012 9:55:31 PM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
    INFO: HHH000422: Disabling contextual LOB creation as connection was null
    avr. 25, 2012 9:55:31 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
    INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
    avr. 25, 2012 9:55:31 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
    INFO: HHH000397: Using ASTQueryTranslatorFactory
    Et après cette dernière ligne, rien, pinuts, nada.

    Sauriez-vous d'où vient mon problème et comment le résoudre ?

    Je vous remercie d'avance pour vos réponses.

  2. #2
    Membre à l'essai
    Profil pro
    Inscrit en
    Juillet 2009
    Messages
    10
    Détails du profil
    Informations personnelles :
    Âge : 34
    Localisation : France

    Informations forums :
    Inscription : Juillet 2009
    Messages : 10
    Points : 11
    Points
    11
    Par défaut
    Oula, il y a de la fatigue dans l'air...

    C'était vraiment très bète :

    J'avais :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Users user = (Users) session.get(Users.class, 1);
    Et il fallait :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Users user = (Users) session.get(Users.class, (short)1);
    Je vais me cacher, désolé pour le dérangement.

  3. #3
    Membre actif Avatar de Jacobian
    Inscrit en
    Février 2008
    Messages
    425
    Détails du profil
    Informations forums :
    Inscription : Février 2008
    Messages : 425
    Points : 245
    Points
    245
    Par défaut
    merci de bien expliquer ton probleme

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

Discussions similaires

  1. [Core] Eclipse : Configuration Hibernate / Oracle 10g Express
    Par Bateau_Ivre dans le forum Hibernate
    Réponses: 4
    Dernier message: 12/08/2012, 15h15
  2. Connexion Hibernate à Oracle 10G Express
    Par mon_proj dans le forum Hibernate
    Réponses: 0
    Dernier message: 10/05/2011, 15h18
  3. Mapping Hibernate Date avec champ date Oracle 10g
    Par tdeco dans le forum Hibernate
    Réponses: 0
    Dernier message: 25/01/2011, 10h28
  4. connection hibernate 3 ,oracle 10g,eclypse europa
    Par walidinfo dans le forum Hibernate
    Réponses: 9
    Dernier message: 24/04/2009, 15h08
  5. Hibernate & Oracle Express 10g
    Par totoprog dans le forum Hibernate
    Réponses: 4
    Dernier message: 16/12/2008, 17h00

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