-->
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.  [ 3 posts ] 
Author Message
 Post subject: Key oder nicht Key, das ist die Frage.
PostPosted: Fri Oct 20, 2006 5:28 am 
Newbie

Joined: Fri Oct 20, 2006 5:06 am
Posts: 7
Hallo!

In meiner ersten Hibernate-Anwendung ist es mir bisher gelungen, alles zu installieren, das Logging zu aktivieren und auch Daten in eine erste Tabelle zu schreiben.

Nun habe ich besagte zwei Zeilen und möchte weitere einfügen, bekomme aber die Fehlermeldung eines "duplicate key":

[java] Hibernate: select max(Id) from Editor
[java] Hibernate: insert into Editor (Name, LoginName, Id) values (?, ?, ?)
[java] 2006-10-20 11:03:49,004 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 1062, SQLState: 23000
[java] 2006-10-20 11:03:49,005 [main] ERROR org.hibernate.util.JDBCExceptionReporter - Duplicate entry 'musterklaus' for key 2
[java] 2006-10-20 11:03:49,017 [main] ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session
[java] org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
[java] at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
[java] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
[java] at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249)
[java] at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
[java] at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
[java] at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
[java] at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
[java] at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
[java] at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
[java] at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
[java] at de.wwu.fuse.fuser2.db.DbConnector.createAndStoreEvent(Unknown Source)
[java] at de.wwu.fuse.fuser2.gui.FuSer2.<init>(Unknown Source)
[java] at de.wwu.fuse.fuser2.gui.FuSer2.main(Unknown Source)
[java] Caused by: java.sql.BatchUpdateException: Duplicate entry 'musterklaus' for key 2
[java] at com.mysql.jdbc.ServerPreparedStatement.executeBatch(ServerPreparedStatement.java:657)
[java] at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
[java] at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
[java] ... 10 more
[java] 2006-10-20 11:03:49,030 [main] FATAL de.wwu.fuse.fuser2.gui.FuSer2 - Fatal Exception!
[java] 2006-10-20 11:03:49,447 [main] INFO de.wwu.fuse.fuser2.gui.FuSer2 - Startup took 9 seconds.

Erstaunlicherweise ist aber die Spalte, in der 'musterklaus' eingefuegt werden soll überhaupt kein Key. Nach meinem Verständnis ist lediglich die Id als Key definiert. Hier das zugehörige Mapping-File:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="de.wwu.fuse.fuser2.db.FuSerUser" table="Editor">
<id name="id" type="int" column="Id">
<generator class="increment" />
</id>
<property name="name" column="Name" />
<property name="loginName" column="LoginName" />
</class>
</hibernate-mapping>

Und der entsprechende Java-Code.

...
dbc.createAndStoreEvent("Klaus Mustermann", "musterklaus");
dbc.createAndStoreEvent("marta Mustermann", "musterfrau");
HibernateUtil.getSessionFactory().close();
...

public void createAndStoreEvent(String name, String loginName) {

Session session = HibernateUtil.getSessionFactory().getCurrentSession();

session.beginTransaction();

FuSerUser fuserUser = new FuSerUser();
fuserUser.setName(name);
fuserUser.setLoginName(loginName);
logger.info("id: "+ fuserUser.getId());

session.save(fuserUser);

session.getTransaction().commit();
}

Das ganze läuft mit der aktuellen Hibernate-Version (3.2.0ga).

Leider habe ich keine Idee mehr, wo ich suchen soll. Handbuch und FAQ verstehe ich so, dass ich alles richtig gemacht habe. Habt ihr vielleicht einen Hinweis?

Vielen Dank!

Johannes Schwall


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 20, 2006 6:07 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
kann es sein das in der Datenbank auf login ein unique key constraint ist?

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 20, 2006 7:13 am 
Newbie

Joined: Fri Oct 20, 2006 5:06 am
Posts: 7
In der Tat, das war das Problem. Vielen Dank!

Johannes


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