-->
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.  [ 4 posts ] 
Author Message
 Post subject: MS SQL Server 2005 JPA Identity Spalte
PostPosted: Tue Feb 12, 2008 6:01 am 
Newbie

Joined: Tue Feb 12, 2008 5:23 am
Posts: 2
Hallo wir verwenden
Hibernate 3.2.5
Hibernate EntityManager 3.3.1
Hibernate Annotations 3.3.0
um DB Zugriffe via JPA zu benutzen.
Die Klassen sind annotiert und werden zur Laufzeit von Hibernate gebunden. Es gibt keine Mapping Dateien

Der Primary Key ist wie folgt definiert
@Id
@GeneratedValue(strategy = IDENTITY)
public Long getId() {
return this.id;
}
ein Insert in die Tabelle führt zu folgender Exception:
SCHWERWIEGEND: Cannot insert explicit value for identity column in table 'Team' when IDENTITY_INSERT is set to OFF.
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not insert: [de.lbsbayern.jpa.test.entity.Team]
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:630)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:219)
at de.lbsbayern.jpa.test.entity.CreatePlayersAndTeamsHibernate.main(CreatePlayersAndTeamsHibernate.java:26)
Caused by: org.hibernate.exception.SQLGrammarException: could not insert: [de.lbsbayern.jpa.test.entity.Team]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:40)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2158)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2638)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:298)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:49)
at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:618)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:592)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:596)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:213)
... 1 more
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot insert explicit value for identity column in table 'Team' when IDENTITY_INSERT is set to OFF.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(Unknown Source)
at com.microsoft.sqlserver.jdbc.IOBuffer.processPackets(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.getPrepExecResponse(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PreparedStatementExecutionRequest.executeStatement(Unknown Source)
at com.microsoft.sqlserver.jdbc.CancelableRequest.execute(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeRequest(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeUpdate(Unknown Source)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:73)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:33)
... 16 more

Was nicht wirklich verwunderlich, da Hibernate für den Insert folgendes SQL Statement benutzt:

insert into Team (id, division, teamName) values (null, ?, ?)

Die Frage ist jetzt wieso wird das o.g Statement erzeugt. Der Sinn einer Identity Spalte ist doch, dass ich sie eben nicht einfügen muss, sondern das DBMS das für mich regelt. Null für eine Id Spalte erscheint doch vollkommen sinnfrei oder.
Vielen Dank im Voraus
Friedbert


Top
 Profile  
 
 Post subject: Microsoft SQL Server 2005
PostPosted: Thu Aug 28, 2008 10:23 pm 
Newbie

Joined: Thu Aug 28, 2008 10:17 pm
Posts: 2
Hallo,

Ich habe die selbe Probleme.
Ich gebrauche Microsoft SQL Server 2005.
Haben Sie die Probleme erschieden?
Wenn ich keine id mit dem Form mitgebe sieht die Fehler so aus:

Caused by: org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): nl.medsen.bea.Test
at org.hibernate.id.Assigned.generate(Assigned.java:33)

Ich begreife nicht warum die org.hibernat.id.Assigned Klasse gebraucht wird.
Warum keine fur Identity?

Ich hoffe Sie wissen etwas.

Danke,

Wilfred


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 29, 2008 1:30 am 
Newbie

Joined: Tue Feb 12, 2008 5:23 am
Posts: 2
Bei uns war das Problem, dass wir den falschen Dialect eingestellt hatten. Ich habe die Standardkonfiguration übernommen und da steht hsql drin. Das ist aber nicht wie ich annahm die HQL sonder der Dialect für die DB hsql. mssql eingetragen (weis nicht mehr genau) und schon gings.
HSQL erwartet null in auto increment Spalten MSSQL erwartet die Spalte überhaupt nicht.
Ich hoffe ich konnte helfen
Friedbert


Top
 Profile  
 
 Post subject: jtds driver fixed problem with mssql server
PostPosted: Fri Aug 29, 2008 9:16 am 
Newbie

Joined: Thu Aug 28, 2008 10:17 pm
Posts: 2
Thanks mr f.

With Microsoft JDBC Driver for SQL Server - sqljdbc.jar I had problems.
But with jtds they are gone.

jtds website:
http://jtds.sourceforge.net/benchTest.html

Driver can be downloaded here:
http://sourceforge.net/project/showfile ... p_id=33291

When using seam setup use:
hibernate.connection.driver_class=net.sourceforge.jtds.jdbc.Driver
hibernate.dialect=org.hibernate.dialect.SQLServerDialect
hibernate.connection.url=jdbc:jtds:<server_type>://<server>[:<port>][/<database>][;<property>=<value>[;...]]


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