5
在我的應用程序中,我有幾個實體POJO使用JPA批註註釋。還配置了hbm2ddl以爲這些實體生成表。當應用程序第一次啓動時,除了一個以外,所有表都成功生成。 這裏的實體源代碼:表不是由hibernate的hbm2ddl創建的
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "REQUESTS")
public class InterpreterRequest implements java.io.Serializable {
private static final long serialVersionUID = -1017432073323298138L;
@Id
@GeneratedValue
private long id;
@Column(name = "quantity")
private int quantity;
@Column(name = "from")
private String from;
@Column(name = "to")
private String to;
@Column(name = "spec")
private String spec;
@ManyToOne(targetEntity = Event.class)
private Event event;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public String getFrom() {
return from;
}
public void setFrom(String from) {
this.from = from;
}
public String getTo() {
return to;
}
public void setTo(String to) {
this.to = to;
}
public String getSpec() {
return spec;
}
public void setSpec(String spec) {
this.spec = spec;
}
public Event getEvent() {
return event;
}
public void setEvent(Event event) {
this.event = event;
}
}
而這裏的Hibernate的Session出廠配置:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
<prop key="hibernate.connection.pool_size">5</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
<!-- <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
<prop key="hibernate.hibernate.cache.use_query_cache">true</prop> -->
</props>
</property>
<property name="annotatedClasses">
<list>
<value>com.ceonline.inter.shared.model.User</value>
...
<value>com.ceonline.inter.shared.model.InterpreterRequest</value>
</list>
</property>
</bean>
有什麼可以爲就是hbm2ddl生成表格時,可以省略InterpreterRequest類的理由?
非常感謝!問題真的是從'保留'字。 – 2011-06-08 23:31:25
是的,我自己也有類似的問題。使用了一些沒有被底層DBMS實現的語句,而且hibernate工作得很好 - 除了一些罕見的不當行爲之外。有趣的調試,特別是如果你假設某個地方會引發異常或至少記錄錯誤。其實我會假設你可以指定/查看這個地方,只是不知道在哪裏。 – Voo 2011-06-09 00:01:07