2

I am working with two databases so while saving the data object in the Table I am getting the following error:

PersistenceException: Error with [models.Task] It has not been enhanced but its superClass [class play.db.ebean.Model] has? (You are not allowed to mix enhancement in a single inheritance hierarchy) marker[play.db.ebean.Model] className[models.Task]

I am using the two Java classes one is Task.class and other is Userdetails.class:

Task.class :

@Entity
@Table(name="third")
public class Task extends Model {

    @Id
    @Column(name="id")
    private int id;

    @Column(name="name")
    private String username;

    public static Finder finduser=new Finder<String,Task>(String.class,Task.class);

}

And Userdetails.class :

@Entity
@Table(name="userdetails")
public class UserDetail extends Model{

    @Id
    @Column(name="id")
    private int id;

    @Column(name="username")
    private String username;
    @Column(name="itemdetail")
    private String itemname;

    public static Finder finduser=new Finder<String,UserDetail (String.class,UserDetail.class);
}

My application.conf file is:

db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost:3306/test?characterEncoding=UTF-8"
db.default.user=root
ebean.default="models.UserDetail"
evolutionplugin=disabled

db.secondary.driver=com.mysql.jdbc.Driver
db.secondary.url="jdbc:mysql://localhost:3306/secondary?characterEncoding=UTF-8"
db.secondary.user=root
ebean.secondary="models.Task"

I have tried some solutions from stackoverflow but still it's not working. Some of them like:

1. @MappedSuperclass
2. ebean.dafault=model.*.*
rtruszk
  • 3,902
  • 13
  • 36
  • 53
Deepanshu
  • 23
  • 1
  • 4

1 Answers1

2

Have you read this SO question?

You did not mention the Play version you are using? The following configuration works for me on Play 2.2.3:

db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost:3306/test?characterEncoding=UTF-8"
db.default.user=xxx
db.default.password="xxx"
ebean.default="models.UserDetail"

db.secondary.driver=com.mysql.jdbc.Driver
db.secondary.url="jdbc:mysql://localhost:3306/secondary?characterEncoding=UTF-8"
db.secondary.user=xxx
db.secondary.password="xxx"
ebean.secondary="models.Task"

The following controller code saves your entities (as they are) to the two databases correctly:

public static Result index() {
    UserDetail userDetail = new UserDetail();
    userDetail.save();

    Task task = new Task();
    task.save("secondary");
}

note that I pass in the server name to the save() method for models.Task. This tells Ebean which datasource to use when saving.

Why are your entities fields private and not public? Did you leave out the getters/setters for brevity or is there another reason? I ask because of this comment

Community
  • 1
  • 1
Donovan Muller
  • 3,822
  • 3
  • 30
  • 54