-->
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: Generate a 'transient' property from hbm.xml
PostPosted: Tue Oct 19, 2004 12:05 pm 
Newbie

Joined: Tue Oct 19, 2004 12:00 pm
Posts: 1
Hibernate version:2.1

Is it possible to generate 'transient' properties from an hbm.xml file? I've got some properties which I want to appear in my value object, but which I don't want to persist to the database. The only solution I can see so far is to use the class-code meta information and hand-code the properties in the hbm.xml file. But it would be nice to be able to specify the property using the <property> syntax and then add an attribute like transient="true" which would then have the effect that the private attribute / public getter & setter is generated in the Java code, but no column is created in the schema and Hibernate doesn't attempt to persist that field.

I'm churning over the philosophical quandries regarding this in my own mind, but so far haven't come up with a better way to design the value objects in order to solve my problem.

Cheers,
C


Top
 Profile  
 
 Post subject: Re: Generate a 'transient' property from hbm.xml
PostPosted: Tue Sep 11, 2012 5:33 am 
Newbie

Joined: Tue Sep 11, 2012 5:29 am
Posts: 2
I have the same problem.
I read (SELECT) from a DB VIEW, and i Need to insert in a DB Table. So i have to define the view fields as transient.
Is it possible to define a transient property in hibernate.hbm.xml file

Tks


Top
 Profile  
 
 Post subject: Re: Generate a 'transient' property from hbm.xml
PostPosted: Sat Sep 15, 2012 12:53 pm 
Beginner
Beginner

Joined: Fri Sep 14, 2012 10:41 am
Posts: 20
My first reaction to your question is: What a strange question?

If you don't want a column to appear in the database, just don't have a <property> entry for it. I have done that many times.

Does that answer you question?


Top
 Profile  
 
 Post subject: Re: Generate a 'transient' property from hbm.xml
PostPosted: Tue Sep 18, 2012 2:51 am 
Newbie

Joined: Tue Sep 11, 2012 5:29 am
Posts: 2
Unfortunately, no.
Meanwhile, thanks for the reply.

I unfortunately have this situation.
Code:
<? Xml version = "1.0"?>
<! DOCTYPE hibernate-mapping PUBLIC "- / / Hibernate / Hibernate Mapping DTD 3.0 / / EN"
                                   "Http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="Pippo.web.entities.Contatti" table="VW_CONTATTI">
id> column="IDCONTATTO" name="Idcontatto" type="int">
<generator class="sequence">
<param name="sequence"> SEQ_IDCONTATTO </ param>
</ Generator>
</ Id>
<property column="CAP" generated="never" lazy="false" name="Cap" type="string"/>
 <property column="COGNOME" generated="never" lazy="false" name="Cognome" type="string"/>
<property column="DATA" generated="never" lazy="false" name="Data" type="date"/>
<property column="IDRUBRICA" generated="never" lazy="false" name="Idrubrica" ​​type="int"/>
<property column="NOME" generated="never" lazy="false" name="Nome" type="string"/>
<property column="VIA" generated="never" lazy="false" name="Via" type="string"/>
<property column="PROPRIETARIO" generated="never" lazy="false" name="Proprietario" type="string" insert="false" update="false" />

<sql-insert> insert into CONTACTS (ZIP, LAST NAME, DATE, IDRUBRICA, NAME, STREET) VALUES (?,?,?,?,?,?) </ sql-insert>
<sql-update> update CONTACTS September CAP =?, SURNAME =?, DATA =?, IDRUBRICA =?, NAME =?, VIA =? where ContactID = </ sql-update>
<sql-delete> delete from CONTACTS where ContactID = </ sql-delete>
</ Class>
<hibernate-mapping>



In particular, look at this line:
Code:
<class name="Pippo.web.entities.Contatti" table="VW_CONTATTI">


As you can see the table reference is VW_CONTATTI, which actually shows a view of the database, not the table CONTATTI. In the view I have additional fields that are not in the table CONTATTI, but that are read from other tables related to contacts (example PROPRIETARIO is read from a table called RUBRICA).

Consequently my Contacts object must contain the PROPRIETARIO property, but this property should not be considered in persistence operations.

I hope I was clear. I'm new to this world (I would not write bestiality) :-)


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.