aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate/Spring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate/Spring" Watch "Hibernate/Spring" New topic
Author

Hibernate/Spring

vijaya sharma
Greenhorn

Joined: Dec 30, 2003
Posts: 15
I am using hibernate 3.0 and spring 1.2.4

When i try to instantiate the Class object using the test(which uses JUnit) with out performing any inserts( just trying to extract the column value)

I get the following Error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'SomeNameObjectSessionFactory' defined in class path resource [some-manualtest-test.xml]: Initialization of bean failed; nested exception is org.hibernate.MappingException: could not instantiate id generator

org.hibernate.MappingException: could not instantiate id generator

I wonder why it should not be able to generate the id,The id generator code extracted from the HBM file is as follows:

<id name="Id" type="long" column="some_id">
<generator class="sequence">
<param name="sequence">some_id_seq</param>
</generator>
</id>

I would be greatly thankful if someone could tell me if there is something wrong, with respect to maybe incompatible versions of hibernate and spring or am i missing something.

Thanks,
Vijay


only thing constant is change
Michael Duffy
Ranch Hand

Joined: Oct 15, 2005
Posts: 163
Originally posted by vijayasharm sharma:
I am using hibernate 3.0 and spring 1.2.4

When i try to instantiate the Class object using the test(which uses JUnit) with out performing any inserts( just trying to extract the column value)

I get the following Error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'SomeNameObjectSessionFactory' defined in class path resource [some-manualtest-test.xml]: Initialization of bean failed; nested exception is org.hibernate.MappingException: could not instantiate id generator

org.hibernate.MappingException: could not instantiate id generator

I wonder why it should not be able to generate the id,The id generator code extracted from the HBM file is as follows:

<id name="Id" type="long" column="some_id">
<generator class="sequence">
<param name="sequence">some_id_seq</param>
</generator>
</id>

I would be greatly thankful if someone could tell me if there is something wrong, with respect to maybe incompatible versions of hibernate and spring or am i missing something.

Thanks,
Vijay


Yes, you're missing something.

Spring and Hibernate are telling you that the database dialect you're using does not support sequences. You didn't say which database you're using, but if it's SQL server the generator class should be "identity". The safest choice would be "native" - let Hibernate decide based on the database.


%
vijaya sharma
Greenhorn

Joined: Dec 30, 2003
Posts: 15
Hi,
Thanks for the reply
I am using spring-xml file where i have configured the dilect property

<bean id="boatsSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="boatsDataSource"/>
</property>

<property name="mappingDirectoryLocations">
<list>
<value></value>
</list>
</property>

<property name="hibernateProperties">
<props>
(See This Line)
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">false</prop>
</props>
</property>
</bean>


As you suggested that i should let hibernate decide, I tried using the native but it didn't work as well.

Do you think there could be somethis else to it.

Thanks in advance.
anuja Edathu
Ranch Hand

Joined: Sep 09, 2005
Posts: 84
Hi vijayasharm ,
Try this if you are using Oracleadatabase, this should work . It works for me

<id name="Id" column="some_id" >

<generator class="increment"/>
</id>
Regards,

Anuja Karthikeyan
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
You should be able to use sequences with Oracle. Check to see if the Oracle account you are accessing the database with has permission to create/access that sequence -- perhaps that is why it is failing.


There is no emoticon for what I am feeling!
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Also, be careful if you use "increment". Quoting from Hibernate in Action:
The generator [increment] is especially efficient if the single-server Hibernate application has exclusive access to the database but shouldn't be used in any other scenario.

[ January 11, 2006: Message edited by: Jeff Albrechtsen ]
vijaya sharma
Greenhorn

Joined: Dec 30, 2003
Posts: 15
Thanks Jeff,Anuja and michael. Identity as the document says works.
 
Consider Paul's rocket mass heater.
 
subject: Hibernate/Spring