-->
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.  [ 6 posts ] 
Author Message
 Post subject: add a property to persistent class
PostPosted: Tue Feb 27, 2007 6:43 am 
Beginner
Beginner

Joined: Thu Aug 10, 2006 2:06 am
Posts: 26
hi all,

i have to add a property to my persistent class at runtime. is there any sample which would help me to use the PersistentClass.addProperty method.

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 27, 2007 7:27 am 
Newbie

Joined: Tue Feb 27, 2007 5:26 am
Posts: 3
// Get the existing mapping for User from Configuration
PersistentClass userMapping = cfg.getClassMapping(User.class);

// Define a new column for the USER table
Column column = new Column();
column.setType(Hibernate.STRING);
column.setName("Krishna");
column.setNullable(false);
column.setUnique(true);
userMapping.getTable().addColumn(column);

// Wrap the column in a Value
SimpleValue value = new SimpleValue();
value.setTable(userMapping.getTable());
value.addColumn(column);
value.setType(Hibernate.STRING);

// Define a new property of the User class
Property prop = new Property();
prop.setValue(value);
prop.setName("Krishna");
userMapping.addProperty(prop);
// Build a new session factory, using the new mapping
SessionFactory sf = cfg.buildSessionFactory();


Hope I am making sense.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 01, 2007 6:23 am 
Beginner
Beginner

Joined: Thu Aug 10, 2006 2:06 am
Posts: 26
hi

i did as u said but now the issue is that my .cfg.xml contains only the id (primary key) and the rest of the column property, i am adding programmatically as you said.

but when i try to save the values in the table by calling session.save, it picks only the id and not the columns.

it creates the query as

insert into teams (TEAM_ID) values (?)

whereas it should create as

insert into teams (TEAM_ID, TEAM_NAME) values (?,?)

(Here TEAM_ID is present in xml and TEAM_NAME, i am adding through configuration)

please let me know what am i missing out. its very urgent.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 02, 2007 12:58 am 
Beginner
Beginner

Joined: Thu Aug 10, 2006 2:06 am
Posts: 26
any clue for the above problem. it is urgent.


Top
 Profile  
 
 Post subject: hi
PostPosted: Tue Mar 13, 2007 6:16 am 
Beginner
Beginner

Joined: Thu Aug 10, 2006 2:06 am
Posts: 26
the above issue was resolved.

but now a new requirement:
I need to add the associations also dynamically just like the way the peoperty was added (as mentioned above). Where can i get some samples for the same.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 28, 2007 1:07 am 
Beginner
Beginner

Joined: Thu Aug 10, 2006 2:06 am
Posts: 26
Hi all,

any idea about the above issue.


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