Hello.
I am trying to use Oracle (Oracle 9.2.0.4) sequences with Hibernate (Hibernate 2.1), and I am having trouble. Can anybody help me?
The MAPPING DEFINITION that I have is the following:
[code]<hibernate-mapping>
...
<id name="id" type="long" unsaved-value="null">
<generator class="sequence">
<param name="sequence">WGWCustomer_sequence</param>
</generator>
</id>
...
</hibernate-mapping>[/code]
And the JAVA CODE that I am usind is the following:
[code]// Creates and initializes the Hibernate session factory
try {
hibernateSessionFactory = new Configuration().configure().buildSessionFactory();
} catch (HibernateException e) {
e.printStackTrace();
System.exit(1);
}
// Creates an Hibernate session
try {
hibSession = hibernateSessionFactory.openSession();
tx = hibSession.beginTransaction();
} catch(Exception e) {
e.printStackTrace();
System.exit(1);
}
// Loads new data
try {
// Create a new Customer
WGWCustomer customer = new WGWCustomer();
customer.setId(???); // How to use the seq?
customer.setName("Telefonica");
customer.setDescription("Operador de Telecomunicaciones");
customer.setDomain("www.telefonica.com");
// Persist the new Customer
hibSession.save(customer);
...
}[/code]
Regarding the XML and Java code given above, I have 2 questions:
1.- How should I use the sequence in the Java code? Do I have to use a customer.setId(???) instruction? Something different?
2.- When I execute the Java code I get the exception:
[code]D:\Proyectos\wgw>wgw_initial_data.bat
net.sf.hibernate.MappingException: could not instantiate id generator
at net.sf.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:82)
at net.sf.hibernate.mapping.SimpleValue.createIdentifierGenerator(SimpleValue.java:82)
at net.sf.hibernate.persister.AbstractEntityPersister.<init>(AbstractEntityPersister.java:630)
at net.sf.hibernate.persister.EntityPersister.<init>(EntityPersister.java:716)
at net.sf.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:42)
at net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:137)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:768)
at es.tid.psstlatam.api.wgw.WGWInitialData.main(WGWInitialData.java:35)
Caused by: net.sf.hibernate.MappingException: Dialect does not support sequences
at net.sf.hibernate.dialect.Dialect.getSequenceNextValString(Dialect.java:319)
at net.sf.hibernate.id.SequenceGenerator.configure(SequenceGenerator.java:62)
at net.sf.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:78)
... 7 more[/code]
So, it seems there is a problem supporting sequences, but my Dialect (hibernate.dialect net.sf.hibernate.dialect.Oracle9Dialect) clearly supports sequences.
Any idea?
Thank you very much, Manuel.
|