|
|
|
Re: Dynamic JPA: How to handle auto generated primary key in Dynamic Type? [message #815957 is a reply to message #815502] |
Thu, 08 March 2012 09:03 |
Nabeel Ahmed Messages: 20 Registered: January 2012 |
Junior Member |
|
|
HI, Thanks for your reply,
I have applied both the approaches you suggested, but it's not working.
For static model i used these two annotations and they work
---------------------------------------------------------------
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
---------------------------------------------------------------
For dynamic model it doesn't work.
---------------------------------------------------------------
JPADynamicTypeBuilder personBuilder = new JPADynamicTypeBuilder(classLoader.createDynamicClass(packageName + "Person"), null, "Person");
personBuilder.setPrimaryKeyFields("pid");
personBuilder.addDirectMapping("pid",int.class, "pid");
personBuilder.addDirectMapping("personName", String.class, "personName");
NativeSequence sequence = new NativeSequence();//new NativeSequence(true);
sequence.setPreallocationSize(1);
personBuilder.configureSequencing(sequence, "SEQ_GEN_IDENTITY", "pid");
The database is same for both the cases, but i got the following error in case of dynamic model:
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'SEQUENCE'.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:196) [sqljdbc4.jar:]
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1454) [sqljdbc4.jar:]
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:388) [sqljdbc4.jar:]
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:338) [sqljdbc4.jar:]
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4026) [sqljdbc4.jar:]
---------------------------------------------------------------------------
I have debug the eclipse link code, it uses the native sequence in case of static model, but I end always with the default sequencing strategy, i.e. a table named SEQUENCE, in case of dynamic although i have configured Native sequence.
any help?
[Updated on: Thu, 08 March 2012 13:48] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03091 seconds