-->
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.  [ 6 posts ] 
Author Message
 Post subject: Cannot insert data
PostPosted: Sat Apr 12, 2008 1:08 pm 
Newbie

Joined: Sat Apr 12, 2008 12:59 pm
Posts: 10
hi,

when I try to insert data into database, the log4j log display the following error messages:

Code:
WARN [org.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:77)] (13-04-2008 02:26:50) - SQL Error: 0, SQLState: S1000
ERROR [org.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:78)] (13-04-2008 02:26:50) - java.lang.ArrayIndexOutOfBoundsException: 6
ERROR [com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:80)] (13-04-2008 02:26:50) - #{LoginAction.doLogin}: javax.faces.el.EvaluationException: org.hibernate.exception.GenericJDBCException: could not insert: [SkyTin.Login.User]
javax.faces.FacesException: #{LoginAction.doLogin}: javax.faces.el.EvaluationException: org.hibernate.exception.GenericJDBCException: could not insert: [SkyTin.Login.User]
...
/* Some error messages .. */
...
Caused by: javax.faces.el.EvaluationException: org.hibernate.exception.GenericJDBCException: could not insert:
...
/* Some error messages .. */


and the catatina.out display the insert command, when i copy it to mysql command prompt and substitute suitable values, it can insert data into database:

Code:
Hibernate:
    insert
    into
        LOGIN
        (LOGIN_ID, USER_ID, LOGIN_DATE, IP_ADDR, IS_SUCCESS)
    values
        (null, ?, ?, ?, ?)


LoginLog.hbm.xml

Code:
<?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="Test.Login.LoginLog" table="LOGIN">
        <id name="LOGIN_ID" column="LOGIN_ID">
            <generator class="native"/>
        </id>
       
        <property name="USER_ID" column="USER_ID"/>
        <property name="LOGIN_DATE" column="LOGIN_DATE"/>
        <property name="IP_ADDR" column="IP_ADDR"/>
        <property name="IS_SUCCESS" column="IS_SUCCESS"/>         

    </class>


</hibernate-mapping>


P.S. it can select data from database, but cannot use save() and saveOrUpdate()

How can I solve it ?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 13, 2008 3:13 am 
Newbie

Joined: Thu Mar 27, 2008 9:43 pm
Posts: 1
Hi,
Please let me know persistence class and hibernate config file properties samples.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 13, 2008 3:52 am 
Newbie

Joined: Sat Apr 12, 2008 12:59 pm
Posts: 10
Hi, now it can insert data into database, but after insert, it display the following error messages:

Code:
ERROR [org.hibernate.AssertionFailure.<init>(AssertionFailure.java:27)] (13-04-2008 15:43:22) - an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)

/* Some error messages here */

Caused by: java.lang.OutOfMemoryError: Java heap space

/* Some error messages here */


User.hbm.xml:
Code:
<?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="SkyTin.Login.User" table="T_USER">

        <id name="id" column="id">
            <generator class="native"/>
        </id>

        <property name="name" column="name"/>

        <property name="age" column="age"/>

    </class>

</hibernate-mapping>


Java code:
Code:
User user = new User();
user.setName("caterpillar");
user.setAge(new Long(30));

Session session = HibernateUtil.getSessionFactory().openSession();
Transaction tx= session.beginTransaction();              

session.save(user);
session.flush();
tx.commit();
session.close();
HibernateUtil.shutdown();


T_USER Table:
Code:
+-------+--------------+------+-----+---------+----------------+
| Field | Type             | Null | Key | Default | Extra          |
+-------+--------------+------+-----+---------+----------------+
| id       | bigint(20)      | NO   | PRI | NULL    | auto_increment |
| name  | varchar(255) | YES  |     | NULL    |                |
| age     | bigint(20)      | YES  |     | NULL    |                |
+-------+--------------+------+-----+---------+----------------+



Command show in Catalina.out
Code:
Hibernate:
    insert
    into
        T_USER
        (name, age)
    values
        (?, ?)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 13, 2008 5:58 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
You missed type in id and age by default it takes string i hope so . .

Try after specifying type

<hibernate-mapping>

<class name="SkyTin.Login.User" table="T_USER">

<id name="id" column="id">
<generator class="native"/>
</id>

<property name="name" column="name"/>

<property name="age" column="age"/>

</class>

</hibernate-mapping>

May be memory leak you are getting out of memory exception.Post your connection related configuration

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 13, 2008 7:23 am 
Newbie

Joined: Sat Apr 12, 2008 12:59 pm
Posts: 10
I was added the type in id and age, but the problem still exists.

User.hbm.xml
Code:
<?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="SkyTin.Login.User" table="T_USER">

        <id name="id" column="id" type="java.lang.Long">
            <generator class="increment"/>
        </id>

        <property name="name" column="name" type="java.lang.String"/>

        <property name="age" column="age" type="java.lang.Long"/>

    </class>

</hibernate-mapping>


hibernate.cfg.xml
Code:
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
   
        <!-- Settings for a local HSQL (testing) database. -->
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost/TEST</property>
        <property name="connection.username">test</property>
        <property name="connection.password">123456</property>

        <!-- Use the C3P0 connection pool. -->
        <property name="c3p0.min_size">3</property>
        <property name="c3p0.max_size">5</property>
        <property name="c3p0.timeout">1800</property>
   
        <!-- Disable second-level cache. -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
        <property name="cache.use_query_cache">false</property>
        <property name="cache.use_minimal_puts">false</property>
        <property name="max_fetch_depth">3</property>
   
        <!-- Print SQL to stdout. -->
        <property name="show_sql">true</property>
        <property name="format_sql">true</property>
   
        <!-- Drop and then re-create schema on SessionFactory build, for testing. -->
        <!--property name="hbm2ddl.auto">create</property-->
   
        <!-- Bind the getCurrentSession() method to the thread. -->
        <property name="current_session_context_class">thread</property>

        <!-- Hibernate XML mapping files -->
        <mapping resource="SkyTin/Login/User.hbm.xml"/>
   
        <!-- Hibernate Annotations (and package-info.java)
        <mapping package="org.mypackage"/>
        <mapping class="org.MyClass/>
        -->

    </session-factory>

</hibernate-configuration>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 14, 2008 1:52 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Plz.. correct mapping

<hibernate-mapping>

<class name="SkyTin.Login.User" table="T_USER">

<id name="id" column="id" type="long">
<generator class="increment"/>
</id>

<property name="name" column="name" type="string"/>

<property name="age" column="age" type="long"/>

</class>

</hibernate-mapping>

And send us detail log ...

_________________
Dharmendra Pandey


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