-->
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: data is not saved to mysql
PostPosted: Thu Oct 13, 2005 5:09 pm 
Newbie

Joined: Sun Oct 02, 2005 3:15 pm
Posts: 5
Location: Brasilia - Brazil
I have a very simple test case, a CategoryType

<code>
public class CategoryType {

private Long id;
private String name;

public CategoryType(String typeName) {
this.name = typeName;
}
public CategoryType() {
}

// methods
get/set name
get/set id
toString/equals/hashCode
</code>

Hibernate version:
3.0.5
Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>
<code>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="br.com.claudius.congrezz.model">
<class name="CategoryType" table="CATEGORYTYPE">
<id column="id" name="id" >
<generator class="identity" />
</id>
<property name="name" column="name" length="60" not-null="true" />
</class>
</hibernate-mapping>
</code>

Code between sessionFactory.openSession() and session.close():
<code>
CategoryType typeEvent = new CategoryType("evento1");
org.hibernate.Transaction tx = hibSession.beginTransaction();
hibSession.save(typeEvent);
tx.commit();
</code>
Full stack trace of any exception that occurs:
no exception.
Name and version of the database you are using:
MySQL 4.1.12 rpm mandriva
Database: Tested wth InnoDB and MyISAM
The generated SQL (show_sql=true):
16:45:15,919 INFO [org.hibernate.connection.DriverManagerConnectionProvider] - Using Hibernate built-in connection pool (not for production use!)
16:45:15,925 INFO [org.hibernate.connection.DriverManagerConnectionProvider] - Hibernate connection pool size: 20
16:45:15,926 INFO [org.hibernate.connection.DriverManagerConnectionProvider] - autocommit mode: false
16:45:15,935 INFO [org.hibernate.connection.DriverManagerConnectionProvider] - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/test?autoReconnect=true
16:45:15,936 INFO [org.hibernate.connection.DriverManagerConnectionProvider] - connection properties: {user=claudio, password=****}
16:45:16,231 INFO [org.hibernate.dialect.Dialect] - Using dialect: org.hibernate.dialect.MySQLInnoDBDialect
16:45:16,242 INFO [org.hibernate.hql.ast.ASTQueryTranslatorFactory] - Using ASTQueryTranslatorFactory
16:45:16,242 INFO [org.hibernate.hql.ast.ASTQueryTranslatorFactory] - Using ASTQueryTranslatorFactory
16:45:16,360 INFO [org.hibernate.impl.SessionFactoryImpl] - building session factory
16:45:16,373 WARN [net.sf.ehcache.config.Configurator] - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/home/claudio/javaSoftware/hibernate-3.0/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
16:45:17,643 INFO [org.hibernate.impl.SessionFactoryObjectFactory] - Not binding factory to JNDI, no JNDI name configured
16:45:17,668 INFO [org.hibernate.impl.SessionFactoryImpl] - Checking 0 named queries
16:45:17,720 DEBUG [org.hibernate.SQL] - insert into CATEGORYTYPE (name) values (?)
16:45:17,720 DEBUG [org.hibernate.SQL] - insert into CATEGORYTYPE (name) values (?)
Hibernate: insert into CATEGORYTYPE (name) values (?)

The problem: the name is not saved into mysql db

The tests were run inside and outside IDE (NetBeans), with JDK 5.
The create-table script (taken from mysql administrative console)
<code>
CREATE TABLE `CATEGORYTYPE` (
`id` bigint(20) NOT NULL auto_increment,
`name` varchar(60) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
</code>

I configured mysql to --log, the output:
<code>
051013 16:45:16 26 Connect claudio@localhost on test
26 Query SET NAMES latin1
26 Query SET character_set_results = NULL
26 Query SHOW VARIABLES
26 Query SHOW COLLATION
26 Query SET autocommit=1
26 Query SET autocommit=0
051013 16:45:17 26 Prepare [1] insert into CATEGORYTYPE (name) values (?)
26 Execute [1] insert into CATEGORYTYPE (name) values (?)
26 Query commit
</code>

Monitored even with ethereal, every line below is a command query (as ethereal sees them), for every command there is a response, that is OK (response from mysql)
<code>
SET NAMES latin1
SET character_set_results = NULL
SHOW VARIABLES
SHOW COLLATION
SET autocommit=1
SET autocommit=0
insert into CATEGORYTYPE (name) values (?)
evento1
//ethereal says: unknown command
commit
</code>

As we can see, appear that everything is fine, excerpt the data is not saved. The property "evento1" is sent to mysql (as ethereal shows).
The id generator is identity.
<code>
mysql> select * from CATEGORYTYPE;
+----+------+
| id | name |
+----+------+
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
+----+------+
5 rows in set (0.00 sec)
</code>

I know this topic is so newbie, but I cannot see where is the problem.

Note this test is run from a standalone application, without a TM.
Please, any advice is really important, thank you.

thanks

Claudio


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 13, 2005 5:10 pm 
Newbie

Joined: Sun Oct 02, 2005 3:15 pm
Posts: 5
Location: Brasilia - Brazil
I found "http://forum.hibernate.org/viewtopic.php?t=948763" to be very close to mine, but my code already uses beginTransaction()


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 13, 2005 6:10 pm 
Newbie

Joined: Sun Oct 02, 2005 3:15 pm
Posts: 5
Location: Brasilia - Brazil
Just to let you know, the test worked fine when changed the database to Apache Derby. strange.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 13, 2005 6:17 pm 
Newbie

Joined: Sun Oct 02, 2005 3:15 pm
Posts: 5
Location: Brasilia - Brazil
And those debug log were printed also:

19:16:58,857 DEBUG [org.hibernate.SQL] - values identity_val_local()
19:16:58,857 DEBUG [org.hibernate.SQL] - values identity_val_local()
Hibernate: values identity_val_local()


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.