Newsletter

Hibernate Many To One Annotation Example

Hibernate » on Aug 30, 2011 { 4 Comments } By Sivateja

Will find the example on hibernate many to one mapping using annotations
Files required…

  • Customers.java
  • Vendor.java
  • hibernate.cfg.xml
  • ForOurLogic.java

Customers.java

Vendor.java

hibernate.cfg.xml

ForOurLogic.java

Output

 

You Might Also Like

  ::. About the Author .::

Java4s_Author
- Full Stack Java/J2EE & UI Web Developer
Founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog, Love Java and UI frameworks.
You can sign-up for the Email Newsletter for your daily dose of Java tutorials.

Comments

4 Responses to “Hibernate Many To One Annotation Example”
  1. ramana says:

    can you post how can we maintain the trasactions in hibernate with explaination?

  2. sandhya says:

    In ForOurLogic.java program on line 49 it must be session.save(c1)… please correct it.. thankyou

  3. manjesh says:

    I learn Spring and hibernate from this website. now I am working spring with hibernate very comfortably..

    Thank you

  4. While executing the above example, I am getting error, Kindly please have a look…

    Exception in thread "main" org.hibernate.MappingException: Unknown entity: org.hibernate_1.Customers
    at org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:1096)
    at org.hibernate.internal.SessionImpl.getEntityPersister(SessionImpl.java:1443)
    at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:116)
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:209)
    at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:194)
    at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
    at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:715)
    at org.hibernate.internal.SessionImpl.save(SessionImpl.java:707)
    at org.hibernate.internal.SessionImpl.save(SessionImpl.java:702)
    at org.hibernate_1.ForOurLogic.main(ForOurLogic.java:41)

Name*
Mail*
Website



By posting your answer, you agree to our comments policy.
Most Recent Posts from Top Categories
Hibernate Spring Struts
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2018 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.