Hibernate and JPA error: duplicate import, try using auto-import=”false”


Using Hibernate and JPA you cannot have two classes with the same name (on different packages) mapped. This raise an error at runtime:
Caused by: org.hibernate.DuplicateMappingException: duplicate import: MyClass refers to both com.intre.MyClass and com.dummy.MyClass (try using auto-import=”false”)

To solve this issue on the Entity annotation  of com.intre.MyClass and com.dummy.Class add the property name.

package com.intre;
@Entity(name = “com.intre.myclass”)
@Table(name = “MyClass”)
public class MyClass …

package com.dummy;
@Entity(name = “com.dummy.myclass”)
@Table(name = “MyClass”)
public class MyClass …

2 thoughts on “Hibernate and JPA error: duplicate import, try using auto-import=”false”

  1. Hi Marcus, yes it’s true but if you want to use just annotation I found only this way. Do you have other solutions using annotations? Should be great! 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s