Get all updates of Java4s

Hibernate Many To Many Mapping Using Annotations

Let us see the example on many to many using annotations

Files required….

  • hibernate.cfg.xml


Eclipse Output

In the database

You Might Also Like

  ::. About the 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.


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

  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(

  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(
    at org.hibernate.cfg.Configuration.parseSessionFactory(
    at org.hibernate.cfg.Configuration.doConfigure(
    at org.hibernate.cfg.Configuration.doConfigure(
    at org.hibernate.cfg.Configuration.configure(
    at com.mapping.ForOurLogic.main(
    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:[org.hibernate.cache.ReadWriteCache$Item]
    at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(
    at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(
    at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(
    at org.hibernate.cfg.CollectionSecondPass.doSecondPass(
    at org.hibernate.cfg.Configuration.secondPassCompile(
    at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(
    at org.hibernate.cfg.Configuration.buildSessionFactory(
    at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(

  6. manoj says:

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


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 - 2018 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.