I still learning about Ebean ORM with Play Framework. have problem with unexpected evolution script that generated by Play!Framework. I'm using Play!Framework 2.1.1 with JDK 1.7 update 5 64-bit. Sorry, for long code snippet in this question.
I have two Ebean Model looks like following:
Course.java
package models;
import play.data.validation.Constraints;
import play.db.ebean.Model;
import javax.persistence.*;
@Entity
@Table(name = "castillo_courses")
public class Course extends Model {
public enum CourseType {
COMPULSORY(1), BASIC_INTEREST(2), ADVANCED_INTEREST(3), THESIS(4);
private int value;
CourseType(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
@Id
private String code;
@Constraints.Required
private String course_name;
@Constraints.Required
private String credits;
@Constraints.Required
private CourseType course_type;
// Ebean finder and Other getter and setter method
......
}
CourseInterest.java
package models;
import play.data.validation.Constraints;
import play.db.ebean.Model;
import javax.persistence.*;
@Entity
@Table(name = "castillo_course_interest")
public class CourseInterest extends Model {
public enum InterestType {
ARCHITECTURAL_INFRA(1), SOFTWARE_TECH(2), INFORMATION_PROCESSING(3), ENTERPRISE_SYSTEM(4), COMP_INTELLIGENCE(5);
private int value;
InterestType(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
@Id
@ManyToOne
@JoinColumn(name = "course_code", referencedColumnName = "code")
private Course course;
@Id
@Constraints.Required
private InterestType interest_type;
// Ebean finder and Other getter and setter method
......
}
This is generated evolution script from the models above:
# --- Created by Ebean DDL
# To stop Ebean DDL generation, remove this comment and start using Evolutions
# --- !Ups
create table castillo_courses (
code varchar(255) not null,
course_name varchar(255),
credits varchar(255),
course_type integer,
constraint ck_castillo_courses_course_type check (course_type in (0,1,2,3)),
constraint pk_castillo_courses primary key (code))
;
create table castillo_course_interest (
course_name varchar(255),
credits varchar(255),
course_type integer,
interest_type integer not null,
constraint ck_castillo_course_interest_course_type check (course_type in (0,1,2,3)),
constraint ck_castillo_course_interest_interest_type check (interest_type in (0,1,2,3,4)))
;
create sequence castillo_courses_seq;
create sequence castillo_course_interest_seq;
# ..... !DOWNS code not shown
What I expected with the generated evolution script is:
In castillo_courses
CREATE TABLE
script, ck_castillo_courses_course_type
constraint should check in (1,2,3,4)
as defined by CourseType.value
attribute, not to check in (0,1,2,3)
. I suspect evolution generated this check by using ORDINAL
value of my Enums.
In castillo_course_interest
CREATE TABLE
script, it define again all castillo_courses
fields except code
. I expect the script is only define course_code
column as defined by @JoinColumn
annotation. There is another problem here. It has no script to generate primary key constraint too, because I have defined two @Id
defined in model.
I appreciate to anyone that can explain, give advice, or help me with this problem.. :)
Kindly regards.