Get all updates of Java4s
Newsletter

Hibernate Many To Many Mapping Using Annotations

Let us see the example on many to many using annotations

Files required….

  • Categories.java
  • Item.java
  • hibernate.cfg.xml
  • ForOurLogic.java

Categories.java

Item.java

hibernate.cfg.xml

ForOurLogic.java

Eclipse Output

In the database

You Might Also Like

Comments

6 Responses to “Hibernate Many To Many Mapping Using Annotations”
  1. sudhakar says:

    Hi java4s,
    This is sudhakar. Greetings for Java4s site maintained holders. This site is very useful for java developers. everything mentions and code display process very brilliant. so I like it this site. my desire was this site maintained very long time and using update technology put in the site for java developers and one more thing best wishes for future implements tickets.

    Thanks & Regards
    Sudhakar

  2. sammaiah says:

    Difference between GenerationType.AUTO and GenerationType.SEQUENCE

  3. Manikandan says:

    Hi java4s,

    I got this error while running your code,

    log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
    log4j:WARN Please initialize the log4j system properly.
    Exception in thread “main” org.hibernate.MappingException: Unknown entity: com.bean.Categories
    at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:489)

  4. churanjeevi says:

    log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
    log4j:WARN Please initialize the log4j system properly.
    Exception in thread "main" org.hibernate.MappingException: An AnnotationConfiguration instance is required to use <mapping class="com.mapping.Categories"/>
    at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1597)
    at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1552)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1531)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1505)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1425)
    at com.mapping.ForOurLogic.main(ForOurLogic.java:18)
    I got this error while running this code.

  5. Sharad says:

    Exception in thread "main" org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.java.Categories.items[org.hibernate.cache.ReadWriteCache$Item]
    at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1068)
    at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:600)
    at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:541)
    at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:43)
    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1130)
    at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:324)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)
    at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)

  6. manoj says:

    sir,
    its not working above code, getting exception,please correct it sir.
    thanking you sir

Name*
Mail*
Website



By posting your answer, you agree to our comments policy.
What would you like to learn today?
Browse these popular technologies
Spring-Boot-tutorials Hibernate tutorials Spring tutorials Struts tutorials Servlets tutorials Ajax tutorials Log4j tutorials jQuery tutorials Json tutorials Core Java tutorials Web Services tutorials AngularJs tutorials
Most Recent Tutorials
Hibernate_Logo Hibernate Recent Posts Spring_Logo Spring Recent Posts Struts_Logo Struts Recent Posts
Contact | About Us | Privacy Policy | Advertise With Us

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