-->
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: Persist the data of more then one class in one table
PostPosted: Sat Nov 03, 2007 11:08 am 
Newbie

Joined: Tue Oct 30, 2007 5:08 am
Posts: 10
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.2.5

Mapping documents: Hibernate Annotations 3.3

Name and version of the database you are using: Oracle 10g



Dear All,

I am having a table named VENDORDETAILS which is having some fields like (ID, NAME, ADDRESS, CREATEDBY, CREATIONDATE, LASTUPDATEDBY, LASTUPDATIONDATE). Now I am having two classes like
Code:
@Entity(name="VENDORDETAILS")
Public class Vender{
   @Id
   @column(name=”ID”)
   private long id;

   @column(name=”NAME”)
   private String name;

   @column(name=”ADDRESSNAME”)
   private String address;
   
   //Getters and setters
}

The class for RecordLog
Code:
Import java.sql.Date;

Public class RecordLog{
   private long createdByUserId;
   private Date creationDate
   private long lastUpdatedByUserId;
   private Date lastUpdationDate;

   //getters & setters.
}


Now my problem is that how can I store the data of two classes in one table as I use the object of RecordLog when ever I need to store the log information in any table. I could not get that how can I use object of this class in the Vendor class. Because in my database I don’t have any separate tables for both this classes. I just want to store the data of both these classes in only one table. So anybody please guide me that how can solve my problem.

Thank you in advance,

_________________
With Best Regards,
Ishaan


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 04, 2007 7:41 am 
Regular
Regular

Joined: Tue Jan 03, 2006 9:20 am
Posts: 74
I assume you want to create a table where you log operations on other tables and want to keep track of which table they were related to?

Why not just store the tablename (or something else that identifies the table) with the log entry?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 05, 2007 2:22 am 
Newbie

Joined: Mon Oct 01, 2007 12:42 pm
Posts: 13
Location: Helsinki, Finland
Use RecordLog as emebbeded object:

Code:
@Entity(name="VENDORDETAILS")
Public class Vender{
   @Id
   @column(name=”ID”)
   private long id;

   @column(name=”NAME”)
   private String name;

   @column(name=”ADDRESSNAME”)
   private String address;

   @Embedded
   private RecordLog recordLog;
   
   //Getters and setters
}


Code:
@Embeddable
Public class RecordLog{
   private long createdByUserId;
   private Date creationDate
   private long lastUpdatedByUserId;
   private Date lastUpdationDate;

   //getters & setters.
}



Additional information can be found from the manual: Embedded objects (aka components)


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.