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
|