Hi,
I'm stuck with this already for some weeks and I don't have the faintest idea what's going wrong. I'm quite desparate as I've wasted so much time already
I use the data model described below (MySQL). I have created the hbm.xml and java classes by reverse engeneering (Eclipse/JBoss Tools) (see example below).
When I try to save tweets, words or events I can see in the log messages that the pk values are generated and that the parameters are bound correctly, but there is nothing ever written to the database. (See the log message at the very ending of the post)
But the strangest thing is that the objects I save to the event_has_words table are stored perfectly (with the generated id from the word and the event table)!?!?! And foremost no exception gets thrown!?!
Any ideas? I'm going crazy!
Best regards,
John
And here is a mapping that doesn't work:
<?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.brotkasting.buki.cep.data.hibernate.entities.Event" table="event" catalog="cep1">
<id name="pkEventsId" type="java.lang.Integer">
<column name="PK_Events_Id" />
<generator class="identity" />
</id>
<many-to-one name="sourceSystems" class="de.brotkasting.buki.cep.data.hibernate.entities.SourceSystems" fetch="select">
<column name="SourceSystems_PK_SourceSystems_Id" not-null="true" />
</many-to-one>
<many-to-one name="tweets" class="de.brotkasting.buki.cep.data.hibernate.entities.Tweets" fetch="select">
<column name="Tweets_pk_tweet_id" not-null="true" />
</many-to-one>
<property name="systemTimeStamp" type="timestamp">
<column name="System_Time_Stamp" length="19" not-null="true" />
</property>
</class>
</hibernate-mapping>
and the according class:
` package de.brotkasting.buki.cep.data.hibernate.entities;
// Generated 28.04.2009 21:24:54 by Hibernate Tools 3.2.4.GA
@Entity @Table(name = "event", catalog = "cep1") public class Event implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = 3530010885697280401L;
private Integer pkEventsId;
private SourceSystems sourceSystems;
private Tweets tweets;
private Date systemTimeStamp;
public Event() {
}
public Event(SourceSystems sourceSystems, Tweets tweets,
Date systemTimeStamp) {
this.sourceSystems = sourceSystems;
this.tweets = tweets;
this.systemTimeStamp = systemTimeStamp;
}
@Id
@Column(name = "PK_Events_Id", unique = true, nullable = false)
public Integer getPkEventsId() {
return this.pkEventsId;
}
public void setPkEventsId(Integer pkEventsId) {
this.pkEventsId = pkEventsId;
}
@JoinColumn(name = "SourceSystems_PK_SourceSystems_Id", nullable = false)
public SourceSystems getSourceSystems() {
return this.sourceSystems;
}
public void setSourceSystems(SourceSystems sourceSystems) {
this.sourceSystems = sourceSystems;
}
@JoinColumn(name = "Tweets_pk_tweet_id", nullable = false)
public Tweets getTweets() {
return this.tweets;
}
public void setTweets(Tweets tweets) {
this.tweets = tweets;
}
//@Temporal(TemporalType.TIMESTAMP)
@Column(name = "System_Time_Stamp", nullable = false, length = 19)
public Date getSystemTimeStamp() {
return this.systemTimeStamp;
}
public void setSystemTimeStamp(Date systemTimeStamp) {
this.systemTimeStamp = systemTimeStamp;
}
} ` and the class to persists
` public class TweetPersistence extends HibernateBase {
private static int batchCounter = 0;
private static void store(Object object) throws HibernateException
{
try {
if(session == null)
{
session = sessionFactory.openSession();
}
if(!session.isOpen())
{
session = sessionFactory.openSession();
}
session.save(object);
LoggingConfigurator.getInstance().info("Objekt:" +object);
//flush cache every 20 saved entities
//if(batchCounter%20 == 0)
//{
session.flush();
session.clear();
//}
//increment batchCounter
batchCounter++;
} catch (HibernateException e) {
e.printStackTrace(System.out);
}
}
public static void storeTweet(Tweets tweet) {
try {
if (tweet != null) {
store(tweet);
}
} catch (HibernateException e) {
e.printStackTrace(System.out);
}
}
} `
and in the log I can see that the ids are generated correctly
- generated identifier: component[eventsPkEventsId,wordsPkWordListId,position]{position=128, wordsPkWordListId=128, eventsPkEventsId=56}