-->
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.  [ 1 post ] 
Author Message
 Post subject: how to set default value in hibernate mapping
PostPosted: Tue Jun 19, 2007 8:31 am 
Beginner
Beginner

Joined: Mon Feb 05, 2007 2:33 am
Posts: 32
Hibernate version: 3.0

Mapping documents:

<?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">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name="com.DAO.account.Account" table="account" catalog="pao">
<id name="accountid" type="java.lang.Integer">
<column name="ACCOUNTID" />
<generator class="native" />
</id>
<many-to-one name="accstatid" column="ACCSTATID" class="com.DAO.account.Accountstatus">
</many-to-one>
<property name="admoid" type="java.lang.Integer">
<column name="ADMOID" />
</property>
<property name="afdnum" type="java.lang.Integer">
<column name="AFDNUM" />
</property>
<property name="area" type="java.lang.Integer">
<column name="AREA" />
</property>
<property name="areaest" type="java.lang.Short">
<column name="AREAEST" />
</property>
<property name="blacklist" type="java.lang.Short">
<column name="BLACKLIST" />
</property>
<property name="blockindicator" type="java.lang.Short">
<column name="BLOCKINDICATOR" />
</property>
<property name="brakod" type="java.lang.String">
<column name="BRAKOD" length="8" />
</property>
<property name="buyingcomb" type="java.lang.Short">
<column name="BUYINGCOMB" />
</property>
<property name="carrier" type="java.lang.Integer">
<column name="CARRIER" />
</property>
<property name="cebnrid" type="java.lang.String">
<column name="CEBNRID" length="4" />
</property>
<property name="changedate" type="java.util.Date">
<column name="CHANGEDATE" length="10" />
</property>
<property name="classid" type="java.lang.String">
<column name="CLASSID" length="10" />
</property>
<property name="closingdays1" type="java.lang.String">
<column name="CLOSINGDAYS1" length="25" />
</property>
<property name="closingdays2" type="java.lang.String">
<column name="CLOSINGDAYS2" length="25" />
</property>
<property name="closingdays3" type="java.lang.String">
<column name="CLOSINGDAYS3" length="25" />
</property>
<property name="closingdays4" type="java.lang.String">
<column name="CLOSINGDAYS4" length="25" />
</property>
<property name="closingdays5" type="java.lang.String">
<column name="CLOSINGDAYS5" length="25" />
</property>
<property name="closingdays6" type="java.lang.String">
<column name="CLOSINGDAYS6" length="25" />
</property>
<property name="closingdays7" type="java.lang.String">
<column name="CLOSINGDAYS7" length="25" />
</property>
<property name="cocnumber" type="java.lang.String">
<column name="COCNUMBER" length="15" />
</property>
<many-to-one name="commid" column="COMMID" class="com.DAO.account.Communication">
</many-to-one>
<property name="createdate" type="java.util.Date">
<column name="CREATEDATE" length="10" />
</property>
<property name="creditcheck" type="java.lang.String">
<column name="CREDITCHECK" length="1" />
</property>
<property name="creditlimit" type="java.lang.Double">
<column name="CREDITLIMIT" precision="14" />
</property>
<property name="creditlimitdate" type="java.util.Date">
<column name="CREDITLIMITDATE" length="10" />
</property>
<many-to-one name="currid" column="CURRID" class="com.DAO.account.Currency">
</many-to-one>
<property name="dagnum" type="java.lang.Integer">
<column name="DAGNUM" />
</property>
<property name="delflag" type="java.lang.Short">
<column name="DELFLAG" />
</property>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

public static void Autoincrementinsert(Object pobject,HttpServletRequest request) {
Session session;
ServletContext context=request.getSession().getServletContext();
SessionFactory _factory = (SessionFactory) context.getAttribute("SESSION_FACTORY_KEY_CRM");
session=_factory.openSession();
try {
Transaction tx = session.beginTransaction();
System.out.println("*****************insert method of hibernate *********************");
int id=(Integer)session.save(pobject);
System.out.println("aa"+id);
request.setAttribute("id", id);
session.flush();
tx.commit();
System.out.println("*****************insert completed *********************");
} catch (HibernateException e) {
System.out.println("Argh ! Error occurred while creating object " + pobject + ": " );
e.printStackTrace();
} finally {
if (session != null && session.isOpen()) {
try {
session.close();
} catch (HibernateException e) {
System.out.println("Ouch ! Error occurred while closing session: ");
e.printStackTrace();
}
}
}
}



Name and version of the database you are using:mysql 5


While inserting a value in the account table how to set a default value as 0 in the delflag field. Whereas i have already specified in the db as default value to 0. but while inserting using hibernate its setting null. how to resolve this problem. please help me.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.