-->
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: <formula> tag
PostPosted: Fri Nov 02, 2007 5:12 am 
Newbie

Joined: Wed Dec 28, 2005 5:44 am
Posts: 12
<formula> tag always inserts NULL in the database (MS SQL) even when a value is entered.
when this <formula> tag is changed to <column> it will insert the given value but in this case when the field is left blank it doesnt enter NULL and hence doesnt store the record in the DB.

Hibernate version: 3.1

Mapping documents:

user.hbm.xml



Code:

<property name="userId" formula="user_id"/>


Code:
public class User{
private Integer userId;
public User(){
}

public Integer getUserId(){
        return userId;
    }

    public void setUserId(Integer userId){
        this.userId = userId;
    }

}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 02, 2007 8:17 am 
Expert
Expert

Joined: Thu Jul 05, 2007 9:38 am
Posts: 287
The formula tag is for defining columns that don't really exist in the database but are calculated. So by definition they are read only.

typical usecases would be constant expressions or some kind of total that gets calculated by some subselect.

regards
J.S.


Top
 Profile  
 
 Post subject: getHibernateTemplate.save(obj) throwing error
PostPosted: Mon Nov 05, 2007 4:44 am 
Newbie

Joined: Wed Dec 28, 2005 5:44 am
Posts: 12
Hi,

This error is a combination of Spring + Hibernate. I have a FK in one of the tables which can accept null. But when this field is left blank the data is not saved in the DB.

This is the error message from the logs -



--------------------------------------------------------------------------------

org.springframework.dao.DataIntegrityViolationException: Hibernate operation: could not insert: [com.java.Department]; SQL [insert into Department (dep_user_id) values (?)]; The INSERT statement conflicted with the FOREIGN KEY constraint "FK_dep_user_id". The conflict occurred in database "x_Dev", table "x.Department", column 'dep_user_id'.; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_dep_user_id". The conflict occurred in database "x_Dev", table "x.Department", column 'dep_user_id'.

--------------------------------------------------------------------------------



Table Details -


code:
--------------------------------------------------------------------------------

<Table Name>User

userid
name
---------------------------
<Table Name>Department

dept_id
dep_user_id <FK>
--------------------------------------------------------------------------------



Hibernate Mapping -


code:
--------------------------------------------------------------------------------

<class name="com.java.Department" table="Department">
<id name="deptid" column="dept_id">
<generator class="native"/></id>
<property name="userid" column="dep_user_id" not-null="false"/></class>

--------------------------------------------------------------------------------



POJO <excerpt> -


code:
--------------------------------------------------------------------------------

public class Department{

private User userid;

public User getUserId() {
return userid;
}

public void setUser(User userid) {
this.userid = userid;
}

--------------------------------------------------------------------------------



Please let me know where am I going wrong.

Thanks,
MJ [/code][/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 05, 2007 9:58 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
let us see you user hbm

_________________
Dharmendra Pandey


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.