简体   繁体   中英

@Column name ignored JPA

Using Google App Engine in conjunction with MySQL

JPA is ignoring my column alias

I've tried declaring on variable:

@Column(name = "fk_location_id") 
private Long locationId;

I've also tried declaring on getter:

@Column(name = "fk_location_id") 
public Long getLocationId() {
    return locationId;
}

I've also tried declaring on both

None work. Just throwing error:

Caused by: org.datanucleus.store.rdbms.exceptions.MissingColumnException: Required columns missing from table fk_location_id

I've googled around and found stuff related to Hibernate but don't believe I'm using that?

Here is my persistence.xml file

<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" />

Here is the schema for table:

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;

How I query the DB:

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 Class:

@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;
}

}

The error tell FKLOCATIONID column not found so its searching for FKLOCATIONID when it should be searching for fk_location_id

Make sure that the @Column annotation is from javax.persistence and not from JDO or somewhere else. DataNucleus can only use either JDO or JPA annotations but not a mix of both

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM