-->
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.  [ 1 post ] 
Author Message
 Post subject: @id and nullable unique in @column
PostPosted: Thu Oct 14, 2010 12:17 pm 
Newbie

Joined: Fri Oct 08, 2010 10:41 am
Posts: 1
I was not able to get my Oracle tables created using a mash-up of spring hibernate annotations. here is how I had my primary key listed:
@Id @GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="ADDRESS_ID", unique=true, nullable=false, precision = 15, scale = 0)
public int getAddressId() {
return this.addressId;
}
The only error I was getting was ORA-00942: table or view does not exist. I was not seeing any errors from schemaexport nor table creation errors what so ever.

My actual error was getting wrapped into invaliddataaccessresourceusageexception and SQLgrammarexception (Could not execute JDBC batch update) errors.

Here is what helped:
Firstly it helped to turn on hibernate logging in log4j.properties as
log4j.logger.org.springframework=DEBUG, DebugAppender, ErrorAppender
log4j.logger.org.hibernate=DEBUG, DebugAppender, ErrorAppender

And the real error was trying to add primary key twice once using @Id and second time using the combination of 'unique=true, nullable=false'.

Here is the real error that i got to finally:

[ERROR 13/10/2010 04:32:02,941] org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:274) - Unsuccessful: create table TAX.ADDRESS (ADDRESS_ID number(19,0) not null unique, ADDRESS_LN1 varchar2(60 char) not null, ADDRESS_LN2 varchar2(60 char), CITY varchar2(30 char) not null, POSTALCODE varchar2(15 char) not null, STATE_PROV_ID number(19,0) not null, primary key (ADDRESS_ID))
[ERROR 13/10/2010 04:32:02,950] org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:275) - ORA-02261: such unique or primary key already exists in the table

Also I changed my annotations to look like this for the primary key:
@Id @GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="ADDRESS_ID")
public int getAddressId() {
return this.addressId;
}

- hope this info helps..

Here is the complete stacktrace:
[ERROR 13/10/2010 04:32:02,941] org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:274) - Unsuccessful: create table TAX.ADDRESS (ADDRESS_ID number(19,0) not null unique, ADDRESS_LN1 varchar2(60 char) not null, ADDRESS_LN2 varchar2(60 char), CITY varchar2(30 char) not null, POSTALCODE varchar2(15 char) not null, STATE_PROV_ID number(19,0) not null, primary key (ADDRESS_ID))
[ERROR 13/10/2010 04:32:02,950] org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:275) - ORA-02261: such unique or primary key already exists in the table

[ERROR 13/10/2010 04:32:03,109] org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:274) - Unsuccessful: create table TAX.STATEPROVINCE (STATE_PROV_ID number(19,0) not null unique, COUNTRYRGN_CODE varchar2(3 char) not null, ISONLYSP_FLAG number(1,0) not null, NAME varchar2(50 char) not null, STATE_PROV_CODE varchar2(3 char) not null, primary key (STATE_PROV_ID))
[ERROR 13/10/2010 04:32:03,111] org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:275) - ORA-02261: such unique or primary key already exists in the table

[ERROR 13/10/2010 04:32:03,239] org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:274) - Unsuccessful: alter table TAX.ADDRESS add constraint FKE66327D4DBFB9E2C foreign key (STATE_PROV_ID) references TAX.STATEPROVINCE
[ERROR 13/10/2010 04:32:03,240] org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:275) - ORA-00942: table or view does not exist

[ERROR 13/10/2010 04:32:04,950] org.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:78) - ORA-00942: table or view does not exist

[ERROR 13/10/2010 04:32:04,952] org.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:78) - ORA-00942: table or view does not exist

[ERROR 13/10/2010 04:32:04,952] org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:301) - Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:92)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:222)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2229)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2665)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:60)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:655)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:732)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:701)
at org.springframework.test.context.transaction.TransactionalTestExecutionListener$TransactionContext.endTransaction(TransactionalTestExecutionListener.java:504)
at org.springframework.test.context.transaction.TransactionalTestExecutionListener.endTransaction(TransactionalTestExecutionListener.java:277)
at org.springframework.test.context.transaction.TransactionalTestExecutionListener.afterTestMethod(TransactionalTestExecutionListener.java:170)
at org.springframework.test.context.TestContextManager.afterTestMethod(TestContextManager.java:344)
at org.springframework.test.context.junit4.SpringMethodRoadie.runAfters(SpringMethodRoadie.java:307)
at org.springframework.test.context.junit4.SpringMethodRoadie$RunBeforesThenTestThenAfters.run(SpringMethodRoadie.java:338)
at org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:217)
at org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:197)
at org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:143)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:160)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:97)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.sql.BatchUpdateException: ORA-00942: table or view does not exist

at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:343)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10720)
at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)
at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
... 39 more


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

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.