Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Question about @SecondaryTable

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I'm trying to use the @SecondaryTable in my app, however, when I try to deploy it this exception arise:
rg.hibernate.AnnotationException: Cannot find the expected secondary table: no animal_state available for test.Animal
at org.hibernate.cfg.Ejb3Column.getJoin(Ejb3Column.java:293)
at org.hibernate.cfg.Ejb3Column.getTable(Ejb3Column.java:272)

at org.hibernate.cfg.annotations.SimpleValueBinder.make(SimpleValueBinder.java:222)
at org.hibernate.cfg.annotations.PropertyBinder.bind(PropertyBinder.java:122)
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1667)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:754)

Here is my code:
@Entity
@Table(name="animals")
@Inheritance(strategy=InheritanceType.JOINED)
@SecondaryTable(name = "animal_states",
pkJoinColumns={
@PrimaryKeyJoinColumn(name="animal_id")})
public class Animal extends EntityBean<Integer> implements Serializable {

protected String name;


@Id
@Column(name="animal_id")
public int getAnimalId() {
return this.beanId.intValue();
}

public void setAnimalId(int id) {
this.beanId = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}



@Transient
public String getEntityKey() {
return new Integer(this.beanId).toString();
}

@Transient
public String getDisplayValue() {
return "Animal";
}

protected int temperature;
@Column(name="temperature", table = "animal_state")
public int getTemperature() {
return temperature;
}

public void setTemperature(int temperature) {
this.temperature = temperature;
}

}

 
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In some places you use "animal_state" while others you use "animal_states"?
 
Laura Barroso
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well Mark, you were rigth...the problem was that I didn't put the name of the table rigth...however when I add another class that inherit from Animal I get this exception :
ERROR [AbstractKernelController] Error installing to Start: name=persistence.unit:unitName=#DataServicePU state=Create
org.hibernate.AssertionFailure: Table animal_state not found

And here is my code:
@Entity
@Table(name="animals")
@Inheritance(strategy=InheritanceType.JOINED)
@SecondaryTable(name = "animal_state",
pkJoinColumns={ @PrimaryKeyJoinColumn(name="animal_id")})
public class Animal extends EntityBean<Integer> {

protected String name;
protected Integer temperature;
public Animal()
{}

@Id
@Column(name="animal_id")
public int getAnimalId() {
return this.beanId.intValue();
}

public void setAnimalId(int id) {
this.beanId = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}



@Transient
public String getEntityKey() {
return new Integer(this.beanId).toString();
}

@Transient
public String getDisplayValue() {
return "Animal";
}


@Column(name="temperature", table = "animal_state",nullable=true)
public int getTemperature() {
return temperature;
}

public void setTemperature(int temperature) {
this.temperature = temperature;
}

}


@Entity
@Table(name="dogs")
@SecondaryTable(name="dog_states",
pkJoinColumns={@PrimaryKeyJoinColumn(name="animal_id")})
public class Dog extends Animal {

private String collarColor;
private String animo;
public Dog() {

}

public String getCollarColor() {
return collarColor;
}

public void setCollarColor(String collarColor) {
this.collarColor = collarColor;
}

/*@Override
@OneToOne
@PrimaryKeyJoinColumn(name="animal_id",referencedColumnName="animal_id")
public DogState getActualState() {
return (DogState) super.getActualState();
}*/


@Column(name = "animo", table="dog_states",nullable=true)
public String getAnimo() {
return animo;
}

public void setAnimo(String animo) {
this.animo = animo;
}

}



 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is a bug in Hibernate :-( It is impossible to use both inheritance of type JOINED and secondary tables... Have a look at http://opensource.atlassian.com/projects/hibernate/browse/HHH-4240.
 
Ranch Hand
Posts: 30
Hibernate Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

In JPA just change the name of entity class , and check no other table exist in database with same name of your Entity class. make table name and Entity class/classes name different.

it will definitely solve your problem.

Prateek Singh
reply
    Bookmark Topic Watch Topic
  • New Topic