나는 Hibernate/JPA에서 작동 시키려고하는 간단한 클래스 계층 구조를 가지고있다.2 개의 테이블 중 최대 절전 모드 엔티티 분할하기
기본적으로 내가 원하는 것은 MovementData가 데이터베이스의 주요 차량 테이블의 정수 ID에 FK를 사용하여 자체 테이블에 있어야한다는 것입니다.
내가 잘못 했나요? 비슷한 다른 것을 어떻게 달성 할 수 있습니까? 나는 JPA 스펙을 따르고 있다고 확신한다. (동작에서 EJB3이 작동합니다 말한다 : 여기에
EJB3 In Action: @SecondaryTable 내가 점점 오전 예외의 일부입니다 :
여기SEVERE: an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: Table MOVEMENT_DATA not found
at org.hibernate.persister.entity.JoinedSubclassEntityPersister.getTableId(JoinedSubclassEntityPersister.java:480)
at org.hibernate.persister.entity.JoinedSubclassEntityPersister.<init>(JoinedSubclassEntityPersister.java:259)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:87)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:261)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327)
가 차량에 관련된 최대 절전 모드에서 로깅 정보의 일부입니다 ... 그것은을 그것을 잘 모든 것을 인식처럼 .. 그 다음은 어떤 이유로 예외를 throw 보인다.
INFO: Binding entity from annotated class: com.dataobject.Vehicle
FINE: Import with entity name Vehicle
INFO: Bind entity com.dataobject.Vehicle on table VEHICLE
INFO: Adding secondary table to entity com.dataobject.Vehicle -> MOVEMENT_DATA
FINE: Processing com.dataobject.Vehicle property annotation
FINE: Processing annotations of com.dataobject.Vehicle.id
FINE: Binding column id. Unique false. Nullable false.
FINE: id is an id
FINE: building SimpleValue for id
FINE: Building property id
FINEST: Cascading id with null
FINE: Bind @Id on id
FINE: Processing annotations of com.dataobject.Vehicle.color
FINE: Binding column COLOR. Unique false. Nullable true.
FINE: binding property color with lazy=false
FINE: building SimpleValue for color
FINE: Building property color
FINEST: Cascading color with null
FINE: Processing annotations of com.dataobject.Vehicle.movementData
FINE: Binding column movementData. Unique false. Nullable true.
FINE: Binding component with path: com.dataobject.Vehicle.movementData
FINE: Processing com.dataobject.MovementData property annotation
FINE: Processing annotations of com.dataobject.MovementData.latitude
FINE: Column(s) overridden for property latitude
FINE: Binding column LATITUDE. Unique false. Nullable true.
FINE: binding property latitude with lazy=false
FINE: building SimpleValue for latitude
FINE: Building property latitude
FINEST: Cascading latitude with null
FINE: Processing annotations of com.dataobject.MovementData.longitude
FINE: Column(s) overridden for property longitude
FINE: Binding column LONGITUDE. Unique false. Nullable true.
FINE: binding property longitude with lazy=false
FINE: building SimpleValue for longitude
FINE: Building property longitude
FINEST: Cascading longitude with null
FINE: Processing annotations of com.dataobject.MovementData.speed
FINE: Column(s) overridden for property speed
FINE: Binding column SPEED. Unique false. Nullable true.
FINE: binding property speed with lazy=false
FINE: building SimpleValue for speed
FINE: Building property speed
FINEST: Cascading speed with null
FINE: Processing annotations of com.dataobject.MovementData.timeOfPosition
FINE: Column(s) overridden for property timeOfPosition
FINE: Binding column TIME_OF_POSITION. Unique false. Nullable true.
FINE: binding property timeOfPosition with lazy=false
FINE: building SimpleValue for timeOfPosition
FINE: Building property timeOfPosition
FINEST: Cascading timeOfPosition with null
FINE: Building property movementData
FINEST: Cascading movementData with null
FINE: Processing annotations of com.dataobject.Vehicle.numWheels
FINE: Binding column NUM_WHEELS. Unique false. Nullable true.
FINE: binding property numWheels with lazy=false
FINE: building SimpleValue for numWheels
FINE: Building property numWheels
FINEST: Cascading numWheels with null
INFO: Binding entity from annotated class: com.dataobject.Car
FINE: Binding column id. Unique false. Nullable false.
FINE: Subclass joined column(s) created
FINE: Import with entity name Car
INFO: Bind entity com.dataobject.Car on table CAR
FINE: Processing com.dataobject.Car property annotation
FINE: Processing annotations of com.dataobject.Car.make
FINE: Binding column MAKE. Unique false. Nullable true.
FINE: binding property make with lazy=false
FINE: building SimpleValue for make
FINE: Building property make
차량은 부모 클래스
0123입니다/**
* Entity implementation class for Entity: Vehicle
*
*/
@Entity
@Table(name="VEHICLE")
@Inheritance(strategy=InheritanceType.JOINED)
@SecondaryTable(name="MOVEMENT_DATA",
pkJoinColumns = {
@PrimaryKeyJoinColumn(name = "ID")
}
)
public class Vehicle implements Serializable {
private int numWheels;
private String color;
private int id;
private MovementData movementData;
private static final long serialVersionUID = 1L;
public Vehicle() {
super();
}
@Embedded
@AttributeOverrides({
@AttributeOverride(
name = "speed",
column = @Column(name = "SPEED",
table = "MOVEMENT_DATA")
),
@AttributeOverride(
name = "timeOfPosition",
column = @Column(name = "TIME_OF_POSITION",
table = "MOVEMENT_DATA")
),
@AttributeOverride(
name = "longitude",
column = @Column(name = "LONGITUDE",
table = "MOVEMENT_DATA")
),
@AttributeOverride(
name = "latitude",
column = @Column(name = "LATITUDE",
table = "MOVEMENT_DATA")
)
})
public MovementData getMovementData() {
return movementData;
}
public void setMovementData(MovementData movementData) {
this.movementData = movementData;
}
@Column(name="NUM_WHEELS")
public int getNumWheels() {
return this.numWheels;
}
public void setNumWheels(int numWheels) {
this.numWheels = numWheels;
}
@Column(name="COLOR")
public String getColor() {
return this.color;
}
public void setColor(String color) {
this.color = color;
}
@Id
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
}
자동차 차량
/**
* Entity implementation class for Entity: Car
*/
@Entity
@Table(name="CAR")
public class Car extends Vehicle implements Serializable {
private String make;
private static final long serialVersionUID = 1L;
public Car() {
super();
}
/**
* @return
*/
@Column(name="MAKE")
public String getMake() {
return this.make;
}
/**
* @param make
*/
public void setMake(String make) {
this.make = make;
}
}
MovementData가 차량에 내장되어 확장
@Embeddable
public class MovementData implements Serializable {
private double speed;
private Date timeOfPosition;
private double latitude;
private double longitude;
private static final long serialVersionUID = 1L;
public MovementData() {
super();
}
/**
* @return
*/
@Column(name="SPEED")
public double getSpeed() {
return this.speed;
}
/**
* @param speed
*/
public void setSpeed(double speed) {
this.speed = speed;
}
/**
* @return
*/
@Column(name="TIME_OF_POSITION")
public Date getTimeOfPosition() {
return this.timeOfPosition;
}
/**
* @param timeOfPosition
*/
public void setTimeOfPosition(Date timeOfPosition) {
this.timeOfPosition = timeOfPosition;
}
/**
* @return
*/
@Column(name="LONGITUDE")
public double getLongitude() {
return this.longitude;
}
/**
* @param longitude
*/
public void setLongitude(double longitude) {
this.longitude = longitude;
}
/**
* @return
*/
@Column(name="LATITUDE")
public double getLatitude() {
return this.latitude;
}
/**
* @param latitude
*/
public void setLatitude(double latitude) {
this.latitude = latitude;
}
}
지속성 단위 :
<properties>
<!-- The database dialect to use -->
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<!-- drop and create tables at deployment -->
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<!-- Hibernate Query Language (HQL) parser. -->
<!-- property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.EhCacheProvider" /-->
<!-- property name="hibernate.cache.provider_class" value="org.hibernate.cache.JbossCacheProvider" /-->
<property name ="hibernate.show_sql" value="false" />
<property name ="hibernate.format_sql" value="false" />
<property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.SingletonEhCacheProvider" />
</properties>
위의 my persistence.xml을 참조하십시오. 난 그냥 대신 업데이 트와 함께 그것을 시도하고, 그것은 여전히 동일한 오류와 함께 작동하지 않습니다. – systemoutprintln
이 문제가있는 다른 사용자를위한 참고 사항 : 자동 선택되었습니다 ...이 작동하지 않습니다. – systemoutprintln