Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to connect to MySql with Hbernate using Eclipse
    primarykey
    data
    text
    <p>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.</p> <p>I was successful to connect MySQL to eclips </p> <h2>Next i wrote simple persistant class person</h2> <p>import javax.persistence.Entity; import javax.persistence.Id;</p> <p>@Entity public class Person {</p> <pre><code>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; } </code></pre> <p>}</p> <hr> <p>Next I wrote a test class for that</p> <pre><code>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(); } } </code></pre> <hr> <p>My Hibernate configuration file</p> <pre><code>&lt;?xml version='1.0' encoding='utf-8'?&gt; &lt;!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt; &lt;hibernate-configuration&gt; &lt;session-factory&gt; &lt;!-- Database connection settings --&gt; &lt;property name="connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt; &lt;property name="connection.url"&gt;jdbc:mysql://localhost:3306/ruwaKuppi&lt;/property&gt; &lt;property name="connection.username"&gt;root&lt;/property&gt; &lt;property name="connection.password"&gt;1234&lt;/property&gt; &lt;property name="hibernate.default_schema"&gt;ruwaKuppi&lt;/property&gt; &lt;!-- JDBC connection pool (use the built-in) --&gt; &lt;property name="connection.pool_size"&gt;2&lt;/property&gt; &lt;!-- SQL dialect --&gt; &lt;property name="dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt; &lt;property name="hibernate.hbm2ddl.auto"&gt;update&lt;/property&gt; &lt;mapping resource="person.hbm.xml"/&gt; &lt;/session-factory&gt; &lt;/hibernate-configuration&gt; </code></pre> <hr> <p>My Mapping file</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&gt; &lt;hibernate-mapping&gt; &lt;class name="Person" table="PERSON"&gt; &lt;id name="id" type="int" column="ID" &gt; &lt;generator class="assigned"/&gt; &lt;/id&gt; &lt;property name="name"&gt; &lt;column name="NAME" /&gt; &lt;/property&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <hr> <p>Now I'm getting this error.... ![enter image description here][2]</p> <p>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)</p> <p>Please can any one help me to get out from this mess... Thank you very much for your concern..</p> <p>p.s :I know that last code is not clear....I think this is the important line of above </p> <p>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)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload