-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to map an auto incremented column (no key)?
PostPosted: Wed Apr 30, 2008 4:31 am 
Newbie

Joined: Wed Apr 30, 2008 4:03 am
Posts: 2
Hi. I have a problem mapping an identity column that is not a key. I donĀ“t want hibernate to insert or update the value from column Number, however I want it to be retrieved.
BR
Alex

--DB SQL Server 2005
CREATE TABLE [dbo].[abc](
[Id] [uniqueidentifier] NOT NULL, --(Primary Key)
[Number] [int] IDENTITY(1,1) NOT NULL,
[Name] [varchar](1)


//Hibernate mapping

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="abc, abc" table="abc" lazy="true">

<id name="Id" column="Id" type="System.Guid" unsaved-value="00000000-0000-0000-0000-000000000000">
<generator class="guid" />
</id>

<property name="Number" column="Number" type="System.Int32" not-null="false" />
<property name="Name" column="Name" type="System.String" not-null="true" />

</class>
</hibernate-mapping>

//c#
public class abc
{
private Guid m_id;
private int m_number;
private string m_name;

public Guid Id
{
get { return m_id; }
set { m_id = value; }
}
public int Number
{
get { return m_number; }
set { m_number = value; }
}
public string Name
{
get { return m_name; }
set { m_name = value; }
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 30, 2008 5:07 am 
Regular
Regular

Joined: Thu Mar 06, 2008 5:06 am
Posts: 68
Hi,
try this:

<property name="Number" column="Number" type="System.Int32" not-null="false" insert="false" update="false" />


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 30, 2008 5:17 am 
Newbie

Joined: Wed Apr 30, 2008 4:03 am
Posts: 2
Thanks a LOT typhos!


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