-->
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: problem with hibernate+mysql with Linux OS
PostPosted: Sun Jun 15, 2008 2:27 pm 
Newbie

Joined: Fri Jun 13, 2008 10:49 am
Posts: 3
Hi everyone.
I'm using mysql 5 and hibernate 3.
but i have some probelm using session.save method.
When I use session.save method in a empty table it inserts a row.
but next session.save istruction doesn't work, it looks that hibernate updates the row and not insert a new one.
And also it doesn't throws an exception if the secon session.save try to insert a row with a duplicated primary key.
I don't understand the problem, even why everything works if I use mysql database in windows xp OS, insetad if it's on Linux Os it doesn't work.

Please, help me and let me know what I can do and let me know if you want that I post some java code or mysql code.

Thanks in advance, Mauro


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 15, 2008 3:39 pm 
Beginner
Beginner

Joined: Tue Dec 12, 2006 6:43 am
Posts: 32
Location: London
Hi,
Do you commit your transaction. Can you please post the mapping class and the code when you do you save if possible.

_________________
Alan Mehio
London
UK


Top
 Profile  
 
 Post subject: problem with hibernate+mysql with Linux OS
PostPosted: Mon Jun 16, 2008 2:52 am 
Newbie

Joined: Fri Jun 13, 2008 10:49 am
Posts: 3
Hi Alan,
sure, I commit it.
here is my code.

my table is
CREATE TABLE `t_conferences` (
`confuri` varchar(255) NOT NULL,
`conf_state` varchar(255),
`mrf_sip_uri` varchar(255),
`confID` varchar(255),
`user_count` int,
/* Keys */
PRIMARY KEY (`confuri`)
) ENGINE = MyISAM;


hibernate.cfg.xml is
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://x.y.z.j:3306/maurodb</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.pool_size">1</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">create</property>
<mapping resource="provaHibernate/Conference.hbm.xml"/>
</session-factory>
</hibernate-configuration>


Conference.hbm.xml

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

<hibernate-mapping>
<class name="provaHibernate.Conference" table="t_conferences">
<id name="confURI">
</id>
<property name="conf_state"/>
<property name="mrf_sip_uri"/>
<property name="confID"/>
<property name="user_count"/>
</class>
</hibernate-mapping>


Conference Java class is
public class Conference {
private String confURI = new String();
private String conf_state = new String();
private String mrf_sip_uri = new String();
private String confID = new String();
private int user_count;

public Conference(String confURI) {
this.confURI = confURI;
this.conf_state = "creating";
this.user_count = 1;
}
public Conference() {
}

public String getConfURI() {
return confURI;
}

public void setConfURI(String confURI) {
this.confURI = confURI;
}

public String getConf_state() {
return conf_state;
}

public void setConf_state(String conf_state) {
this.conf_state = conf_state;
}

public String getMrf_sip_uri() {
return mrf_sip_uri;
}

public void setMrf_sip_uri(String mrf_sip_uri) {
this.mrf_sip_uri = mrf_sip_uri;
}

public String getConfID() {
return confID;
}

public void setConfID(String confID) {
this.confID = confID;
}

public int getUser_count() {
return user_count;
}

public void setUser_count(int user_count) {
this.user_count = user_count;
}

}


and main is
System.out.println("Conference Unit Test");

Session session=new Configuration().configure().buildSessionFactory().openSession();

//Creo una nuova conference
Conference conf=new Conference();
conf.setConfURI("conf5");
conf.setConf_state("creating");
conf.setMrf_sip_uri("mrf2");
conf.setConfID("id1");
conf.setUser_count(2);

//Utilizziamo un modello transazionale dichiarativo
session.beginTransaction();

//Chiedo al middleware di cancellare questo oggetto nel database
//session.delete(conf);
//Chiedo al middleware di salvare questo oggetto nel database
session.save(conf);

//fine della transazione: salviamo tramite commit()
session.getTransaction().commit();

System.out.println("Done");


Please, I hope that you can help me.

Mauro
[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 17, 2008 3:42 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Is confuri your primary key? And you are always setting it to the same value? If that's the case, you'll always effect the same record.

Why not use an auto-generation strategy for the primary key?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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.