-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: PROBLEMS WITH ORACLE SEQUENCES
PostPosted: Thu Jun 24, 2004 6:15 am 
Newbie

Joined: Thu Jun 24, 2004 5:53 am
Posts: 4
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.


Top
 Profile  
 
 Post subject: (MORE INFO) PROBLEMS WITH ORACLE SEQUENCES
PostPosted: Thu Jun 24, 2004 6:54 am 
Newbie

Joined: Thu Jun 24, 2004 5:53 am
Posts: 4
More information regarding the problem with Oracle sequences:

It seems to me that the Java code:

[code]hibernateSessionFactory = new Configuration().configure().buildSessionFactory(); [/code]
is not fetching the Dialect correctly.

I say this because I have added the following:

[code]try {
hibernateSessionFactory = new Configuration().configure().buildSessionFactory();
dialect = Dialect.getDialect();
System.out.println("Supports seqs? "+dialect.supportsSequences());
} catch (HibernateException e) {
e.printStackTrace();
System.exit(1);
}[/code]

and I get the exception:

[code]net.sf.hibernate.HibernateException: [color=red]The dialect was not set. Set the property hibernate.dialect.[/color]
at net.sf.hibernate.dialect.Dialect.getDialect(Dialect.java:354)
at es.tid.psstlatam.api.wgw.WGWInitialData.main(WGWInitialData.java:39)[/code]

which clearly determines that the Dialect is not beeing set.

My XML configuration file is in the CLASSPATH, and it has the following information:

[code]<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>
<session-factory>
<!-- connection to oracle database -->
<property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@10.95.85.196:1521:GENEVA53</property>
<property name="hibernate.connection.username">wgw</property>
<property name="hibernate.connection.password">wgw</property>
<!-- other properties -->
<property name="hibernate.show_sql">true</property>
<property name="hibernate.dialect">net.sf.hibernate.dialect.Oracle9Dialect</property>
<!-- connection pooling -->
<!-- hibernate provides C3PO connection pooling, but this is not suitable for production envs -->
<property name="hibernate.c3po.min_size">5</property>
<property name="hibernate.c3po.max_size">20</property>
<property name="hibernate.c3po.timeout">1800</property>
<property name="hibernate.c3po.max_statements">50</property>

<!-- Mapping files -->
<mapping resource="WGWAuditTrail.hbm.xml"/>
<mapping resource="WGWCustomer.hbm.xml"/>
...
</session-factory>
</hibernate-configuration>[/code]

I have also tried to do the following in the Java code:

[code]hibernateSessionFactory = new Configuration().configure(new File("<path>\\hibernate.cfg.xml")).buildSessionFactory();[/code]
and I doesn't work either!

Any idea? Thank you, Manuel.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 24, 2004 8:06 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
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);


you do not have to call setId(), it will be done by calling session.save(obj)

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.