-->
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: Error in Save
PostPosted: Sun Jun 28, 2009 10:09 pm 
Newbie

Joined: Sun Jun 28, 2009 9:58 pm
Posts: 3
The Error message is:
-------------------------------------------------------------------
Hibernate: insert into TBL_S_USER_MASTER (PASSWORD, NAME, KANA) values (?, ?, ?)
WARN [Thread-5] (JDBCExceptionReporter.java:77) - SQL Error: 515, SQLState: 23000
ERROR [Thread-5] (JDBCExceptionReporter.java:78) - 値 NULL を列 'USERID'、テーブル 'Sandeep.dbo.TBL_S_USER_MASTER' に挿入しようとしましたが、この列は NULL を挿入できません。 INSERT は失敗します。

-------------------------------------------------------------------
The japanese msg means -
This row cannot insert NULL though it tried to insert value NULL in row 'USERID' and table 'Sandeep.dbo.TBL_S_USER_MASTER'. INSERT fails.

--------------------------------------
UserMaster class Hibernate Mapping
--------------------------------------
<hibernate-mapping auto-import="true" default-lazy="false" default-cascade="none" default-access="property">
<class name="entities.UserMaster" table="TBL_S_USER_MASTER" mutable="true" polymorphism="implicit" dynamic-update="true" dynamic-insert="true" select-before-update="false" optimistic-lock="version">

<id name="userId" type="java.lang.String" column="USERID">
<generator class="native" />
</id>

<property name="pwd" type="java.lang.String" column="PASSWORD" not-null="true" length="8" unique="false" optimistic-lock="true" lazy="false" generated="never"/>

<property name="name" type="java.lang.String" column="NAME" not-null="false" length="40" unique="false" optimistic-lock="true" lazy="false" generated="never"/>

<property name="kana" type="java.lang.String" column="KANA" not-null="false" length="40" unique="false" optimistic-lock="true" lazy="false" generated="never"/>

<set name="details" inverse="true" cascade="save-update">
<key column="userId"></key>
<one-to-many class="entities.UserMasterDetails"/>
</set>

</class>
</hibernate-mapping>
-------------------------------------------------
UserMasterDetails class Hibernate mapping
-------------------------------------------------
<hibernate-mapping auto-import="true" default-lazy="false" default-cascade="none" default-access="property">

<class name="entities.UserMasterDetails" table="TBL_S_USER_MASTER_DETAILS" mutable="true" polymorphism="implicit" dynamic-update="false" dynamic-insert="false" select-before-update="false" optimistic-lock="version">

<id name="mgmtId" type="int" column="MGMTID" unsaved-value="null">
<generator class="native"/>
</id>

<property name="userId" type="java.lang.String" column="USERID" not-null="true" length="8" unique="false" optimistic-lock="true" lazy="false" generated="never"/>

<property name="dob" type="java.util.Date" column="DOB" not-null="false" unique="false" optimistic-lock="true" lazy="false" generated="never"/>

<property name="committee" type="java.lang.String" column="COMMITTEE" not-null="false" length="40" unique="false" optimistic-lock="true" lazy="false" generated="never"/>

<many-to-one name="userMaster" class="entities.UserMaster" column="userId" not-null="true" update="false" insert="false"></many-to-one>
</class>

</hibernate-mapping>


and the CODING is-

public boolean SaveorUpdateUser(UserMaster user, UserMasterDetails userDetails){
/* Retrieve Hibernate Session */
Session session = null;
try {
HibernateUtil.createSessionFactory();
session = HibernateUtil.getSession();

} catch (Exception ex) {
ex.printStackTrace();
}
try {
// Begin Hibernate Session
Transaction transaction = session.beginTransaction();
transaction.begin();
System.out.println(user.getUserId());
System.out.println(user.getPwd());
System.out.println(user.getName());
System.out.println(user.getKana());
String usId = null;
usId = user.getUserId();
user.setUserId(usId);
user.getDetails().add(userDetails);
//System.out.println("Session getidentifier:"+session.getIdentifier(user));
session.save(user);

transaction.commit();
transaction = session.beginTransaction();
userDetails.setMgmtId(1);
session.save(userDetails);
transaction.commit();
session.close();

}
catch(Exception e)
{
e.printStackTrace();

}

finally {
session.close();
}

return true;
}

#########################

I am very New to Hibernate and Struts both..

All i know is, I created classes and then mapped in hibernate, created associations between the classes.
Then i got the data from a FORM
I set the values to the class objects
and i simply Save the object instance using hibernate session...
Isnt this all?
WHAT MISTAKE have i made??

ANY HELP please??

#########################


Top
 Profile  
 
 Post subject: Re: Error in Save
PostPosted: Mon Jun 29, 2009 1:56 am 
Newbie

Joined: Tue Jun 23, 2009 3:31 am
Posts: 10
Can u enable the show_sql propery and check the queries?
Could u post the queries generated by Hibernate, which will be helpful to give appropriate solution?


Top
 Profile  
 
 Post subject: Re: Error in Save
PostPosted: Mon Jun 29, 2009 2:09 am 
Newbie

Joined: Sun Jun 28, 2009 9:58 pm
Posts: 3
senthil_rect wrote:
Can u enable the show_sql propery and check the queries?
Could u post the queries generated by Hibernate, which will be helpful to give appropriate solution?


Thank you for going through my post.
But I think i kind of got the solution. Though i still dont know why the error occured.

I changed the Hibernate mapping property..

<id name="userId" type="java.lang.String" column="USERID">
<generator class="assigned"/>
</id>

So now i can insert the data, and i have to set the ID by myself.

THANK YOU AGAIN.


Top
 Profile  
 
 Post subject: Re: Error in Save
PostPosted: Mon Jun 29, 2009 2:54 am 
Newbie

Joined: Sun Jun 28, 2009 9:58 pm
Posts: 3
ONE MORE PROBLEM

I was able to INSERT data in the first table, TBL_S_USER_MASTER
However, there was a problem in inserting data in 2nd table again..(TBL_S_USER_MASTER_DETAILS)

QEURY:

Hibernate: insert into TBL_S_USER (PASSWORD, NAME, KANA, USERID) values (?, ?, ?, ?)
Hibernate: insert into TBL_S_USER_DETAILS (USERID, DOB, COMMITTEE, MGMTID) values (?, ?, ?, ?)

ERROR MESSAGE:

WARN [Thread-5] (JDBCExceptionReporter.java:77) - SQL Error: 544, SQLState: S0001
ERROR [Thread-5] (JDBCExceptionReporter.java:78) - IDENTITY_INSERT が OFF に設定されているときは、テーブル 'TBL_S_USER_DETAILS' の ID 列に明示的に値を挿入することはできません。
ERROR [Thread-5] (AbstractFlushingEventListener.java:301) - Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: could not insert: [entities.UserMasterDetails]

*japanese means..

When IDENTITY_INSERT is set to turning off, the value cannot be inserted in the ID row of table 'TBL_S_USER_DETAILS' specifying it.

*I did execute a command in SQL SERVER,
SET IDENTITY_INSERT dbo.TBL_S_USER_MASTER_DETAILS ON
But it has no effect
WHY ???
Why this error?


ANY thing needed in Hibernate mapping as well?
i did change the hibernate mapping of UserMasterDetails to..

<hibernate-mapping auto-import="true" default-lazy="false" default-cascade="none" default-access="property">

<class name="entities.UserMasterDetails" table="TBL_S_USER_DETAILS" mutable="true" polymorphism="implicit" dynamic-update="false" dynamic-insert="false" select-before-update="false" optimistic-lock="version">

<id name="mgmtId" type="int" column="MGMTID" unsaved-value="null">
<generator class="increment"/>
</id>


<property name="userId" type="java.lang.String" column="USERID" not-null="true" length="8" unique="false" optimistic-lock="true" lazy="false" generated="never"/>

<property name="dob" type="java.util.Date" column="DOB" not-null="false" unique="false" optimistic-lock="true" lazy="false" generated="never"/>

<property name="committee" type="java.lang.String" column="COMMITTEE" not-null="false" length="40" unique="false" optimistic-lock="true" lazy="false" generated="never"/>

<many-to-one name="userMaster" class="entities.UserMaster" column="userId" not-null="true" update="false" insert="false"></many-to-one>
</class>

</hibernate-mapping>


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.