将Google App Engine与MySQL结合使用
JPA忽略了我的列别名
我试过声明变量:
@Column(name = "fk_location_id")
private Long locationId;
我也试过在getter上声明:
@Column(name = "fk_location_id")
public Long getLocationId() {
return locationId;
}
我也尝试过宣布
没有工作。只是抛出错误:
Caused by: org.datanucleus.store.rdbms.exceptions.MissingColumnException: Required columns missing from table fk_location_id
我已经google了一下,找到了与Hibernate相关的内容,但不相信我正在使用它?
这是我的persistence.xml文件
<property name="datanucleus.ConnectionDriverName" value="com.mysql.jdbc.Driver" />
<property name="datanucleus.ConnectionURL" value="jdbc://mydb..." />
<property name="datanucleus.ConnectionUserName" value="user" />
<property name="datanucleus.ConnectionPassword" value="pass" />
<property name="datanucleus.autoStartMechanism" value="None" />
<property name="datanucleus.validateTables" value="true" />
<property name="datanucleus.validateConstraints" value="true" />
<property name="datanucleus.validateColumns" value="true" />
<property name="datanucleus.DetachAllOnCommit" value="true" />
<property name="datanucleus.maxFetchDepth" value="1" />
<property name="datanucleus.storeManagerType" value="rdbms" />
以下是表格的架构:
CREATE TABLE `sites` (
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(255) CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL,
`fk_location_id` bigint(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
我如何查询数据库:
EntityManagerFactory factory;
factory = Persistence.createEntityManagerFactory(Globals.PERSISTENCE_UNIT_NAME);
EntityManager em = factory.createEntityManager();
Query q = em.createQuery("select t from Site t");
List<Site> siteList = q.getResultList();
Java类:
@Entity
@Table(name = "sites")
public class Site {
private Long id;
private String name;
private Long locationId;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Long getLocationId() {
return locationId;
}
public void setLocationId(Long locationId) {
this.locationId = locationId;
}
}
错误告诉FKLOCATIONID列未找到,因此当它应该搜索fk_location_id时搜索FKLOCATIONID
答案 0 :(得分:0)
确保@Column
注释来自javax.persistence
,而不是来自JDO或其他地方。 DataNucleus只能使用JDO或JPA注释,但不能同时使用两者