-->
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.  [ 11 posts ] 
Author Message
 Post subject: problem with primary key generation
PostPosted: Sat Jan 08, 2005 5:53 pm 
Beginner
Beginner

Joined: Thu Dec 02, 2004 4:49 am
Posts: 32
Hibernate version:2.1.6

Mapping documents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping schema="myschema"
package="com.test.impl">
<class name="User" table="USER_DETAIL">
<id name="id" type="int" column="USER_ID">
<generator class="increment" />
</id>

<property name="loginId" type="string" length="15"
column="LOGIN_ID">
</property>

<property name="password" type="string" length="20"
column="PASSWORD" />
<property name="emailId" type="string" length="50"
column="EMAIL_ID" />
<property name="active" type="boolean" column="IS_ACTIVE" />
<property name="lastUpdateUserId" type="int"
column="LAST_UPD_USER_ID" not-null="false" />
<property name="lastUpdateTimestamp" type="calendar"
column="LAST_UPD_TIMESTAMP" not-null="true" />
<set name="rolesSet" table="USER_ROLE_MAP" access="field">
<key column="USER_ID" />
<many-to-many column="ROLE_ID" class="Role" />
</set>
<set name="groupsSet" table="USER_GROUP_MAP" access="field">
<key column="USER_ID" />
<many-to-many column="GROUP_ID" class="Group" />
</set>
<many-to-one name="defaultPrintDevice" class="PrintDevice" column="DEF_PRINT_DEV_ID"></many-to-one>
<many-to-one name="defaultPreviewDevice" class="PrintDevice" column="DEF_PREVIEW_DEV_ID"></many-to-one>
</class>


<class name="PrintDevice" table="PRINT_DEVICE">
<id name="id" type="int" column="PRINT_DEVICE_ID">
<generator class="increment" />
</id>
<property name="name" type="string" length="50"
column="PRINT_DEVICE_NAME" />
<property name="previewable" type="boolean"
column="PREVIEWABLE" />
<property name="printDeviceType" type="string" length="20"
column="PRINT_DEVICE_TYPE" />
<property name="lastUpdateUserId" type="int"
column="LAST_UPD_USER_ID" not-null="true" />
<property name="lastUpdateTimestamp" type="calendar"
column="LAST_UPD_TIMESTAMP" not-null="true" />
</class>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:
Oracle 9.2.*


The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


I am using JBoss 3.2.1 and Spring 1.1.3
i created the database by using the above mapping doc.(I have lot of other persistent classes also..)
the problem i am getting is the "increment" generator is inrementing primary keys one by one in the user_detail table. but in the other tables, hibernate is generting very lengthy primary keys which are not even integers. SO whenever i select some records i am getting ArrayIndexOutOfBoundsException.
another question is why is it working properly in user_detail table?

I tried "native", "identity","sequence" also..none of them worked. ie. they are generating strange primary keys..what is wrong with my mapping?

plz help

Thanks,
SSSS.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 08, 2005 6:12 pm 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Well - what is the max value that is present in one of the 'problematic' tables? The Incremental generator just does a retrival of the max value and then increments this.

Try: select max([column name]) from [tablename]

What database are you using? There may be better alternatives to the incremental generator.

Remember that this generator does not necessarily return int values. This is mentioned in the reference.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 08, 2005 6:21 pm 
Beginner
Beginner

Joined: Thu Dec 02, 2004 4:49 am
Posts: 32
I am using oracle 9.0.1.1.1 and oracle driver is oracle JDBC driver 9.2.0.3.0

i am gettig that problem after inserting the first record itself.
hibernate returns 1. but stores something else in the table.
later, if i try to insert one more record, it throws ArrayIndexOutOfBoundsException..it is really puzzling me..


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 08, 2005 6:32 pm 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
SSSS wrote:
hibernate returns 1.

Where do you see this. Enable debug level logging for hibernate, post the log file and the code.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 08, 2005 6:48 pm 
Beginner
Beginner

Joined: Thu Dec 02, 2004 4:49 am
Posts: 32
This is my code:

public DataSource createDataSource(String name)
DataSource dataSource = new DataSource();
dataSource.setName(name);
dataSource.setLastUpdateUserId(getLoggedInUser());
dataSource.setCreatedDate(Calendar.getInstance());
dataSource.setLastUpdateTimestamp(Calendar.getInstance());
if(canCreateDataSource(dataSource)) {
throw new DataSourceException("");
} else{
productionDao.createDataSource(dataSource);
}
return dataSource;
}

DAO:

public void createDataSource(DataSource dataSource) {
getHibernateTemplate().save(dataSource);
}

i was able to insert the first record successfully...the primary key is generated as
35000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

then i tried again to create another record then i got the following exception



Loading XML bean definitions from file [C:\WebService\WEB-INF\applicationContext.xml]
- Bean factory for application context [org.springframework.context.support.FileSystemXmlApplicationContext;hashCode=397372140]: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [dataSource,sessionFactory,transactionManager,roleDao,userDao,workflowDao,productionDao,facade,userManagerTarget]; Root of BeanFactory hierarchy
- 9 beans defined in ApplicationContext [org.springframework.context.support.FileSystemXmlApplicationContext;hashCode=397372140]
- No MessageSource found for context [org.springframework.context.support.FileSystemXmlApplicationContext;hashCode=397372140]: using empty default
- No ApplicationEventMulticaster found for context [org.springframework.context.support.FileSystemXmlApplicationContext;hashCode=397372140]: using default
- Refreshing listeners
- Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [dataSource,sessionFactory,transactionManager,roleDao,userDao,workflowDao,productionDao,facade,userManagerTarget]; Root of BeanFactory hierarchy]
- Creating shared instance of singleton bean 'dataSource'
- Loaded JDBC driver: oracle.jdbc.driver.OracleDriver
- Creating shared instance of singleton bean 'sessionFactory'
- Hibernate 2.1.6
- hibernate.properties not found
- using CGLIB reflection optimizer
- Mapping class: com.test.webservice.impl.User -> USER_DETAIL
- Mapping collection: com.test.webservice.impl.User.rolesSet -> USER_ROLE_MAP
- Mapping collection: com.test.webservice.impl.User.groupsSet -> USER_GROUP_MAP
- Mapping class: com.test.webservice.impl.Group -> GROUP_DETAIL
- Mapping collection: com.test.webservice.impl.Group.membersSet -> USER_GROUP_MAP
- Mapping collection: com.test.webservice.impl.Group.rolesSet -> GROUP_ROLE_MAP
- Mapping class: com.test.webservice.databean.SubGroup -> SUB_GROUP
- Mapping class: com.test.webservice.impl.Role -> ROLE
- Mapping collection: com.test.webservice.impl.Role.privilegesSet -> ROLE_PRIV_MAP
- Mapping class: com.test.webservice.impl.Privilege -> PRIVILEGE
- Mapping class: com.test.webservice.impl.Notification -> NOTIFICATION
- Mapping collection: com.test.webservice.impl.Notification.users -> NOTIFICATION_USERS
- Mapping collection: com.test.webservice.impl.Notification.groups -> NOTIFICATION_GROUP
- Mapping class: com.test.webservice.impl.State -> STATE
- Mapping collection: com.test.webservice.impl.State.notificationsSet -> STATE_NOTIFICATION
- Mapping class: com.test.webservice.databean.StateMap -> STATE_MAP
- Mapping class: com.test.webservice.impl.DataSource -> DATASOURCE
- Mapping collection: com.test.webservice.impl.DataSource.rolesSet -> DATASOURCE_ROLE_MAP
- Mapping collection: com.test.webservice.impl.DataSource.printJobsSet -> PRINTJOB_DATASOURC
- Mapping class: com.test.webservice.impl.PrintDevice -> PRINT_DEVICE
- Mapping class: com.test.webservice.databean.PrintJobDeviceMap -> PRINTJOB_PRINTDEV
- Mapping class: com.test.webservice.impl.PrintJob -> PRINTJOB
- Mapping collection: com.test.webservice.impl.PrintJob.dataSourcesSet -> PRINTJOB_DATASOURC
- Mapping class: com.test.webservice.impl.Publication -> PUBLICATION
- Mapping class: com.test.webservice.impl.Category -> CATEGORY
- Mapping class: com.test.webservice.databean.SubCategory -> SUB_CATEGORY
- Mapping class: com.test.webservice.impl.Annotation -> ANNOTATION
- Mapping class: com.test.webservice.databean.AnnotationMap -> ANNOTATION_MAP
- Mapping class: com.test.webservice.databean.CategoryMap -> CATEGORY_MAP
- Mapping class: com.test.webservice.databean.EntityType -> ENTITY_TYPE
- Mapping class: com.test.webservice.impl.AuditTrail -> AUDIT_TRAIL
- Mapping class: com.test.webservice.databean.SystemProperties -> SYSTEM_PROPERTIES
- Mapping class: com.test.webservice.databean.Properties -> PROPERTIES
- Building new Hibernate SessionFactory
- processing one-to-many association mappings
- Mapping collection: com.test.webservice.impl.Group.subgroupsSet -> SUB_GROUP
- Mapping collection: com.test.webservice.impl.Group.parentsSet -> SUB_GROUP
- Mapping collection: com.test.webservice.impl.PrintJob.printDevicesSet -> PRINTJOB_PRINTDEV
- Mapping collection: com.test.webservice.impl.Category.children -> SUB_CATEGORY
- Mapping collection: com.test.webservice.impl.Category.parents -> SUB_CATEGORY
- processing one-to-one association property references
- processing foreign key constraints
- Using dialect: net.sf.hibernate.dialect.OracleDialect
- Use outer join fetching: true
- Initializing connection provider: org.springframework.orm.hibernate.LocalDataSourceConnectionProvider
- No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
- Use scrollable result sets: true
- Use JDBC3 getGeneratedKeys(): false
- Optimize cache for minimal puts: false
- echoing all SQL to stdout
- Query language substitutions: {}
- cache provider: net.sf.hibernate.cache.EhCacheProvider
- instantiating and configuring caches
- building session factory
- Not binding factory to JNDI, no JNDI name configured
- Using dialect: net.sf.hibernate.dialect.OracleDialect
- Initializing connection provider: org.springframework.orm.hibernate.LocalDataSourceConnectionProvider
- Running hbm2ddl schema update
- fetching database metadata
- updating schema
- processing one-to-many association mappings
- processing one-to-one association property references
- processing foreign key constraints
- schema update complete
- Creating shared instance of singleton bean 'transactionManager'
- Using DataSource [org.springframework.jdbc.datasource.DriverManagerDataSource@3d302aed] of Hibernate SessionFactory for HibernateTransactionManager
- Creating shared instance of singleton bean 'roleDao'
- Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
- Creating shared instance of singleton bean 'DB2'
- Creating shared instance of singleton bean 'HSQL'
- Creating shared instance of singleton bean 'MS-SQL'
- Creating shared instance of singleton bean 'MySQL'
- Creating shared instance of singleton bean 'Oracle'
- Creating shared instance of singleton bean 'Informix'
- Creating shared instance of singleton bean 'PostgreSQL'
- Creating shared instance of singleton bean 'Sybase'
- SQLErrorCodes loaded: [HSQL Database Engine, Oracle, Sybase SQL Server, Microsoft SQL Server, Informix Dynamic Server, PostgreSQL, DB2*, MySQL]
- Looking up default SQLErrorCodes for DataSource
- Database Product Name is Oracle
- Driver Version is 9.2.0.3.0
- Creating shared instance of singleton bean 'userDao'
- Looking up default SQLErrorCodes for DataSource
- Database product name found in cache for DataSource [org.springframework.jdbc.datasource.DriverManagerDataSource@3d302aed]. Name is 'Oracle'.
- Creating shared instance of singleton bean 'workflowDao'
- Looking up default SQLErrorCodes for DataSource
- Database product name found in cache for DataSource [org.springframework.jdbc.datasource.DriverManagerDataSource@3d302aed]. Name is 'Oracle'.
- Creating shared instance of singleton bean 'productionDao'
- Looking up default SQLErrorCodes for DataSource
- Database product name found in cache for DataSource [org.springframework.jdbc.datasource.DriverManagerDataSource@3d302aed]. Name is 'Oracle'.
- Creating shared instance of singleton bean 'facade'
- Creating shared instance of singleton bean 'userManagerTarget'
Hibernate: select datasource0_.DATASOURCE_ID as DATASOUR1_, datasource0_.DATASOURCE_NAME as DATASOUR2_, datasource0_.CREATED_DATE as CREATED_3_, datasource0_.LAST_UPD_USER_ID as LAST_UPD4_, datasource0_.LAST_UPD_TIMESTAMP as LAST_UPD5_ from myschema.DATASOURCE datasource0_ where (datasource0_.DATASOURCE_NAME=? )
- SQL Error: 0, SQLState: null
- Overflow Exception
- Could not save object
java.sql.SQLException: Overflow Exception
at oracle.sql.NUMBER.toLong(NUMBER.java:376)
at oracle.jdbc.dbaccess.DBConversion.NumberBytesToLong(DBConversion.java:2915)
at oracle.jdbc.driver.OracleStatement.getLongValue(OracleStatement.java:4562)
at oracle.jdbc.driver.OracleResultSetImpl.getLong(OracleResultSetImpl.java:555)
at net.sf.hibernate.id.IncrementGenerator.getNext(IncrementGenerator.java:69)
at net.sf.hibernate.id.IncrementGenerator.generate(IncrementGenerator.java:42)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:765)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:738)
at org.springframework.orm.hibernate.HibernateTemplate$11.doInHibernate(HibernateTemplate.java:301)
at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:176)
at org.springframework.orm.hibernate.HibernateTemplate.save(HibernateTemplate.java:298)
at com.test.webservice.dao.ProductionDAO.createDataSource(ProductionDAO.java:88)
at com.test.webservice.ProductionServiceImpl.createDataSource(ProductionServiceImpl.java:791)
at com.test.webservice.ProductionServiceImpl.main(ProductionServiceImpl.java:1494)
- Unable to translate SQLException with errorCode '0', will now try the fallback translator
- Translating SQLException with SQLState 'null' and errorCode '0' and message [Overflow Exception]; SQL was [] for task [Hibernate operation]
Exception in thread "main" org.springframework.jdbc.UncategorizedSQLException: (Hibernate operation): encountered SQLException [Overflow Exception]; nested exception is java.sql.SQLException: Overflow Exception
java.sql.SQLException: Overflow Exception
at oracle.sql.NUMBER.toLong(NUMBER.java:376)
at oracle.jdbc.dbaccess.DBConversion.NumberBytesToLong(DBConversion.java:2915)
at oracle.jdbc.driver.OracleStatement.getLongValue(OracleStatement.java:4562)
at oracle.jdbc.driver.OracleResultSetImpl.getLong(OracleResultSetImpl.java:555)
at net.sf.hibernate.id.IncrementGenerator.getNext(IncrementGenerator.java:69)
at net.sf.hibernate.id.IncrementGenerator.generate(IncrementGenerator.java:42)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:765)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:738)
at org.springframework.orm.hibernate.HibernateTemplate$11.doInHibernate(HibernateTemplate.java:301)
at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:176)
at org.springframework.orm.hibernate.HibernateTemplate.save(HibernateTemplate.java:298)
at com.test.webservice.dao.ProductionDAO.createDataSource(ProductionDAO.java:88)
at com.test.webservice.ProductionServiceImpl.createDataSource(ProductionServiceImpl.java:791)
at com.test.webservice.ProductionServiceImpl.main(ProductionServiceImpl.java:1494)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 08, 2005 7:00 pm 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Before you do the first insert, what is the value of this expression:

select max(datasource_id) from myschema.DATASOURCE

Also - you haven't showed me the mapping for datasource which seems to be the main table involved here.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 08, 2005 11:07 pm 
Beginner
Beginner

Joined: Thu Dec 02, 2004 4:49 am
Posts: 32
select max(datasource_id) from group1.datasource
this query is returning
35000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.

and the mapping is like this for DataSource.

<class name="DataSource" table="DATASOURCE">
<id name="id" type="int" column="DATASOURCE_ID">
<generator class="increment" />
</id>
<property name="name" type="string" length="50"
column="DATASOURCE_NAME" />
<property name="createdDate" type="calendar"
column="CREATED_DATE" />
<property name="dataSourceType" type="string" length="10"
column="DATASOURCE_TYPE" />
<property name="outputFormat" type="string" length="30"
column="OUTPUT_FORMAT" />
<property name="retentionPeriod" type="long"
column="RETENTION_PERIOD" />
<property name="lastUpdateUserId" type="int"
column="LAST_UPD_USER_ID" not-null="true" />
<property name="lastUpdateTimestamp" type="calendar"
column="LAST_UPD_TIMESTAMP" not-null="true" />
<set name="rolesSet" table="DATASOURCE_ROLE_MAP"
access="field">
<key column="DATASOURCE_ID" />
<many-to-many column="ROLE_ID" class="Role" />
</set>
<set name="printJobsSet" table="PRINTJOB_DATASOURC" access="field">
<key column="DATASOURCE_ID" />
<many-to-many column="PRINTJOB_ID" class="PrintJob" />
</set>

</class>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 10, 2005 8:51 am 
Beginner
Beginner

Joined: Thu Dec 02, 2004 4:49 am
Posts: 32
I forgot to mention perhaps the most important thing.
Actually, I'm developing a webservice in Axis.
All the persistent classes I delcared in the Hibernate mapping doc are the objects that will be sent to the client of the webservice.

So all the persistent classes have some code generated by Axis like Serializer, Deserializer. Also, Axis has overridden the equals and hashcode methods for all my persistent classes.

Is it a problem??

Plz help


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 10, 2005 4:43 pm 
Beginner
Beginner

Joined: Thu Dec 02, 2004 4:49 am
Posts: 32
Is my question vague? what more info should i give?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 6:18 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Have you sorted this out? I am interested in the outcome. If you haven't, I would recommend breaking it down to the simplest case - just the DataSource object mapping and a standalone hibernate app that inserts a few rows. Should be easier to debug.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 14, 2005 11:20 am 
Beginner
Beginner

Joined: Thu Dec 02, 2004 4:49 am
Posts: 32
Ya...that was resolved by replacing my ojdbc14.jar with classes12.zip

has anyone got this kind of problems? also, I am not sure if classes12.zip also has this kind of problems...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 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.