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: Problem with @Entity
PostPosted: Fri Sep 11, 2009 4:52 am 
Newbie

Joined: Fri Sep 11, 2009 2:35 am
Posts: 2
Hi,
I am new to hibernate and i am looking out for a help. I tired the hibernate working with *.hbm.xml and *.cfg.xml files. I am now trying to run a sample using hibernate.properties and @Entity in the classes. I face a problem here I tried to minimize the using *.hbm.xml file instead I opted to use @Entity in class, etc.

Will the @Entity can work without the use of *.hbm.xml files.?
please help me regarding this fix.

Thanks in advance
Hari

_________________
--
Hari


Top
 Profile  
 
 Post subject: Re: Problem with @Entity
PostPosted: Fri Sep 11, 2009 6:24 am 
Newbie

Joined: Thu Sep 03, 2009 3:10 am
Posts: 5
Sure you can use entities by only using annotations. The *.hm.xml are create if you reverse engineer a existing database and can be used to forward engineer to a database. But its just a choice you make using the xml or completely annotation based.

For example:
Code:
@Entity
@Table(name="myTable", catalog="myDB")
public class myEntity {

   @Id
   @GeneratedValue
   @Column(name = "id", nullable = false)
   private Integer id;

   @Column(name = "street", nullable = false)
   private String street;

   @Column(name = "city", nullable = false)
   private String city;

   public myEntity() { };

   public String getStreet() {return this.street;}
   public void setStreet(String street) {this.street = street;}

   public String getCity() {return this.city;}
   public void setCity(String street) {this.city = city;}
}



Take a look at the hibernate documentation there you can find examples of the annotation you can use.


Top
 Profile  
 
 Post subject: Re: Problem with @Entity
PostPosted: Sat Sep 12, 2009 10:34 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Quote:
Will the @Entity can work without the use of *.hbm.xml files.?


Well, I wrote an entire book based on that fact!

Annotations really make working with Hibernate so much easier. It's not a solution for every problem, but it is a great tool to have around.

In one example in my book, I map the following database using Hibernate and JPA annotations. The Java classes end up looking very clean and concise.

Image

You can take a look at some of the JPA an annotation mappings at this little online hibernate tutorial:

http://jpa.ezhibernate.com/Javacode/lea ... itymapping

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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.