-->
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: JPA, Identity-Column als Timestamp
PostPosted: Wed Jan 06, 2010 8:29 am 
Newbie

Joined: Mon Jul 21, 2008 5:52 am
Posts: 13
Hallo Forum,

ich bin dabei eine Messdatenerfassung umzusetzen, und habe eine Tabelle zur Speicherung der Messdaten in MySQL.

--- cut (gekürzt) ---
CREATE TABLE IF NOT EXISTS `daten_aktuell` (
`zeitpunkt` timestamp NOT NULL default CURRENT_TIMESTAMP COMMENT 'Zeitpunkt der Daten',
`sensor_1` double NOT NULL default '0' COMMENT 'Temperatur Kollektor',
`sensor_2` double NOT NULL default '0' COMMENT 'Temperatur Puffer 1 oben',
...
PRIMARY KEY (`zeitpunkt`),
UNIQUE KEY `Zeitpunkt` (`zeitpunkt`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--- cut ---

Dazu gibt es eine Java-Klasse:

--- cut ---
@Entity
@Table(name="daten_aktuell")
public class DatenAktuell {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Temporal(TemporalType.TIMESTAMP)
@Column(name="zeitpunkt", nullable=false, insertable=false, updatable=false, unique=true)
private Timestamp zeitpunkt;
@Column(name="sensor_1", nullable=true)
Double sensor1;
@Column(name="sensor_2", nullable=true)
Double sensor2;
...
--- cut ---

Beim speichern einer neuen Entity erhalte ich folgende Exception:

--- cut ---
Caused by: org.hibernate.HibernateException: The database returned no natively generated identity value
at org.hibernate.id.IdentifierGeneratorFactory.getGeneratedIdentity(IdentifierGeneratorFactory.java:90)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:98)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:57)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2186)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2666)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:321)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:49)
at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:154)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:110)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:645)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:619)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:623)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:220)
--- cut ---

Probiert habe ich es auch mit den anderen GenerationTypes aber ohne Erfolg.

Gibt es eine Möglichkeit, in Java die Timestamp-Column als ID Spalte zu nutzen, oder muss ich eine weitere Spalte mit künstlichen Schlüssel anlegen?

Vielen Dank für eure Hilfe,

Robert


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.