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:
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:
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:
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:
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:
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. :triste:
Sauriez-vous d'où vient mon problème et comment le résoudre ?
Je vous remercie d'avance pour vos réponses.