-->
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 let the nhibernate insert default value into databse.
PostPosted: Thu May 01, 2008 9:37 am 
Newbie

Joined: Sun Jan 27, 2008 4:26 pm
Posts: 18
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
1.2.1
Mapping documents:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace PackagesAndChannelsApp.Model
{
public class ChannelPackage
{
private int chPackID;
private int packageID;
private int channelID;
private DateTime? firstCreated;
private Package package1 = null;
private Channel channel1 = null;

public ChannelPackage()
{
}

public virtual int ChPackID
{
get
{
return this.chPackID;
}
set
{
this.chPackID = value;
}
}
public virtual int PackageID
{
get
{
return package1.PackageID;
}
set
{
this.packageID = value;
}
}
public virtual int ChannelID
{
get
{
return channel1.ChannelID;
}
set
{
this.channelID = value;
}
}
public virtual DateTime? FirstCreated
{
get
{
return this.firstCreated;
}
set
{
this.firstCreated = value;
}
}
public virtual Package Package
{
get
{
return this.package1;
}
set
{
this.package1 = value;
this.package1.PackageID = value.PackageID;
}
}
public virtual Channel Channel
{
get
{
return this.channel1;
}
set
{
this.channel1 = value;
this.channel1.ChannelID = value.ChannelID;
}
}
public virtual string PackageName
{
get
{
return package1.PackageName;
}
}
public virtual string ChannelName
{
get
{
return channel1.ChannelName;
}
}
}
}

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="PackagesAndChannelsApp" assembly="PackagesAndChannelsApp" auto-import="true">
<class name="PackagesAndChannelsApp.Model.ChannelPackage,PackagesAndChannelsApp" table="ChannelPackage" lazy="true" mutable="true">
<id name="ChPackID" column="ChPackID" type="int">
<generator class="native"></generator>
</id>
<many-to-one name="Package" column="PackageID" class="PackagesAndChannelsApp.Model.Package" cascade="none" not-null="true" fetch="select"/>
<many-to-one name="Channel" column="ChannelID" class="PackagesAndChannelsApp.Model.Channel" cascade="none" not-null="true" fetch="select"/>
<property name="FirstCreated" column="FirstCreated" type="DateTime" not-null="true"/>
</class>
</hibernate-mapping>

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

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:



Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html

Hi,I am trying to insert values into databse table.Here is the situation.i have two integer fields and one datetime field.In databse default Datetime is today's date.In my application when i try to insert two integer values (without datetime value which is default value in database) i am getting error like.

not-null property references a null or transient value: PackagesAndChannelsApp.Model.ChannelPackage.FirstCreated
Could you please tell me how to insert into databse with this situation.


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.