Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6672815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:33:09+00:00 2026-05-26T03:33:09+00:00

I’m new to the hibernate and eclipse. I successfully did it with Derby by

  • 0

I’m new to the hibernate and eclipse. I successfully did it with Derby by watching a youtube video. Now I want to do it with MySql.

I was successful to connect MySQL to eclips

Next i wrote simple persistant class person

import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class Person {

private String name;
private int id;


public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
@Id
public int getId() {
    return id;
}
public void setId(int id) {
    this.id = id;
}

}


Next I wrote a test class for that

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;


public class PersonTest {

    /**
     * @param args
     */
    public static void main(String[] args) {

        AnnotationConfiguration cfg = new AnnotationConfiguration();
        cfg.addAnnotatedClass(Person.class);
        cfg.configure("hibernate.cfg.xml");

        new SchemaExport(cfg).create(true, true);

        SessionFactory factory = cfg.buildSessionFactory();
        Session session = factory.getCurrentSession();
        session.beginTransaction();

        Person person = new Person();

        person.setName("Alex");
        person.setId(1);

        session.save(cfg);
        session.getTransaction().commit();

    }

}

My Hibernate configuration file

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

    <session-factory>

        <!-- Database connection settings -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/ruwaKuppi</property>
        <property name="connection.username">root</property>
        <property name="connection.password">1234</property>
        <property name="hibernate.default_schema">ruwaKuppi</property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">2</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.hbm2ddl.auto">update</property>
        <mapping resource="person.hbm.xml"/>

    </session-factory>

</hibernate-configuration>

My Mapping file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC 
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
  <class name="Person" table="PERSON">
   <id name="id" type="int" column="ID" >
   <generator class="assigned"/>
  </id>

  <property name="name">
   <column name="NAME" />
  </property>

 </class>
</hibernate-mapping>

Now I’m getting this error….
![enter image description here][2]

13:13:17,795 INFO Version:15 – Hibernate Annotations 3.4.0.GA
13:13:17,818 INFO Environment:560 – Hibernate 3.3.2.GA
13:13:17,821 INFO Environment:593 – hibernate.properties not found
13:13:17,825 INFO Environment:771 – Bytecode provider name : javassist
13:13:17,830 INFO Environment:652 – using JDK 1.4 java.sql.Timestamp handling
13:13:17,927 INFO Version:14 – Hibernate Commons Annotations 3.1.0.GA
13:13:17,949 INFO Configuration:1474 – configuring from resource: hibernate.cfg.xml
13:13:17,950 INFO Configuration:1451 – Configuration resource: hibernate.cfg.xml
13:13:18,059 INFO Configuration:600 – Reading mappings from resource : person.hbm.xml
13:13:18,147 INFO Configuration:1589 – Configured SessionFactory: null
13:13:18,173 INFO Dialect:175 – Using dialect: org.hibernate.dialect.MySQLDialect
13:13:18,307 INFO HbmBinder:322 – Mapping class: Person -> PERSON
13:13:18,326 INFO AnnotationBinder:419 – Binding entity from annotated class: Person
13:13:18,364 INFO Mappings:161 – duplicate import: Person->Person
13:13:18,367 INFO EntityBinder:422 – Bind entity Person on table Person
Exception in thread “main” org.hibernate.DuplicateMappingException: Duplicate class/entity mapping Person
at org.hibernate.cfg.Mappings.addClass(Mappings.java:141)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:789)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:546)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:291)
at org.hibernate.cfg.Configuration.generateDropSchemaScript(Configuration.java:803)
at org.hibernate.tool.hbm2ddl.SchemaExport.(SchemaExport.java:128)
at org.hibernate.tool.hbm2ddl.SchemaExport.(SchemaExport.java:91)
at PersonTest.main(PersonTest.java:18)

Please can any one help me to get out from this mess… Thank you very much for your concern..

p.s :I know that last code is not clear….I think this is the important line of above

13:13:18,367 INFO EntityBinder:422 – Bind entity Person on table Person
Exception in thread “main” org.hibernate.DuplicateMappingException: Duplicate class/entity mapping Person
at org.hibernate.cfg.Mappings.addClass(Mappings.java:141)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:33:10+00:00Added an answer on May 26, 2026 at 3:33 am

    You tell Hibernate to load the mapping from the hibernate.cfg.xml file:

    cfg.configure("hibernate.cfg.xml");
    

    But you also tell it to add the Person class as a mapped-trough annotations entity:

    cfg.addAnnotatedClass(Person.class);
    

    Decide if you want to map the Person entity using annotations or using XML. If you choose XML, then remove the cfg.addAnnotatedClass(Person.class); line. If you choose annotations, then remove the <class name="Person" table="PERSON"> (and all its sub-elements of course) from the XML file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i want to parse a xhtml file and display in UITableView. what is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.