Estoy intentando crear una tabla con una clave compuesta en Spring utilizando Hibernate, lo que sucede es que me saca el siguiente error:
2017-09-14 09:07:55.323 ERROR 9108 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000388: Unsuccessful: create table fieldevents (is_required boolean not null, position integer not null, event_id tinyblob, field_id integer not null, primary key (event_id, field_id))
2017-09-14 09:07:55.324 ERROR 9108 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaUpdate : BLOB/TEXT column 'event_id' used in key specification without a key length
El key de event
es un int
auto incrementable pero no sé por qué me lo está tomando como un tipo tinyblob
.
El código que estoy utilizando es el siguiente:
@Entity
@Table(name="Events")
public class Event {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Size(max=200)
@Column(name="id", length=200)
private int id;
private boolean active;
@Temporal(TemporalType.TIMESTAMP)
private Date creationDate;
private Date endingDate;
@Size(max=2000)
private String footer;
@Size(max=2000)
private String header;
private String image;
private String logo;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "event", fetch = FetchType.LAZY)
private Set<Mail> mails;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "event", fetch = FetchType.LAZY)
@JsonManagedReference(value="event-Field")
private Set<FieldEvent> eventfields = new HashSet<>();
@NotNull
@Size(max=150)
private String name;
private Date startDate;
public Set<FieldEvent> getEventfields() {
return eventfields;
}
public void setEventfields(Set<FieldEvent> eventfields) {
this.eventfields = eventfields;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Date getEndingDate() {
return endingDate;
}
public void setEndingDate(Date endingDate) {
this.endingDate = endingDate;
}
public String getFooter() {
return footer;
}
public void setFooter(String footer) {
this.footer = footer;
}
public String getHeader() {
return header;
}
public void setHeader(String header) {
this.header = header;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getLogo() {
return logo;
}
public void setLogo(String logo) {
this.logo = logo;
}
public Set<Mail> getMails() {
return mails;
}
public void setMails(Set<Mail> mails) {
this.mails = mails;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
}
@Entity
@Table(name="Fields")
public class Field {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String name;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "field", fetch = FetchType.LAZY)
@JsonManagedReference(value="field-Event")
private Set<FieldEvent> fieldEvents;
public Set<FieldEvent> getFieldEvents() {
return fieldEvents;
}
public void setFieldEvents(Set<FieldEvent> fieldEvents) {
this.fieldEvents = fieldEvents;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@Entity
@Table(name="fieldevents")
@IdClass(FieldEventId.class)
public class FieldEvent {
@Id
@ManyToOne
@PrimaryKeyJoinColumn(name="eventId", referencedColumnName="ID")
@JsonBackReference(value="event-Field")
private Event event;
@Id
@ManyToOne
@PrimaryKeyJoinColumn(name="fieldId", referencedColumnName="ID")
@JsonBackReference(value="field-Event")
private Field field;
private boolean isRequired;
private int position;
public Event getEvent() {
return event;
}
public void setEvent(Event event) {
this.event = event;
}
public Field getField() {
return field;
}
public void setField(Field field) {
this.field = field;
}
public boolean isRequired() {
return isRequired;
}
public void setRequired(boolean isRequired) {
this.isRequired = isRequired;
}
public int getPosition() {
return position;
}
public void setPosition(int position) {
this.position = position;
}
}
public class FieldEventId implements Serializable{
private static final long serialVersionUID = 1L;
private Event event;
private Field field;
public Event getEvent() {
return event;
}
public void setEvent(Event event) {
this.event = event;
}
public Field getField() {
return field;
}
public void setField(Field field) {
this.field = field;
}
@Override
public int hashCode() {
// TODO Auto-generated method stub
return super.hashCode();
}
@Override
public boolean equals(Object obj) {
// TODO Auto-generated method stub
return super.equals(obj);
}
@Override
public String toString() {
// TODO Auto-generated method stub
return super.toString();
}
}