收到以下错误:
<openjpa-2.2.2-r422266:1468616 fatal user error> org.apache.openjpa.persistence.ArgumentException: "com.qbe.asia.ebusiness.admin.intermediary.Intermediary.employees<element:class com.qbe.asia.ebusiness.admin.intermediary.Employee>" declares a column that is not compatible with the expected type "varchar". Column details:
Full Name: TINT_STAFF.STAFF_ID
Type: blob
Size: 0
Default: null
Not Null: false
中介,JAVA
@Entity
@Table( name = "TINTERMEDIARY" )
public class Intermediary {
@Id
@Column(name="INTERMEDIARY_ID")
private String intermediaryId;
@ManyToMany
@JoinTable(name="TINT_STAFF",
joinColumns = {
@JoinColumn(name = "INTERMEDIARY_ID"),
@JoinColumn(name = "STAFF_ID")},
inverseJoinColumns = {
@JoinColumn(name = "STAFF_ID""),
@JoinColumn(name = "INTERMEDIARY_ID")})
private List<Employee> employees;
}
Employee.java
@Entity
@Table(name="TSTAFFMEMBER")
public class Employee {
@Id
@Column(name="STAFF_ID")
private String employeeId;
@ManyToMany (mappedBy = "employees")
private List<Intermediary> intermediaries;
}
TINT_STAFF表
CREATE TABLE TINT_STAFF
(
INTERMEDIARY_ID CHAR(19) NOT NULL,
STAFF_ID CHAR(19) NOT NULL,
PRIMARY KEY ( INTERMEDIARY_ID, STAFF_ID )
);
所有id字段在其他表中也是CHAR(19)。
没有关联映射就像魅力一样,但是只要我通过TINT_STAFF表添加ManyToMany,就会说列是blob ..但事实并非如此。为什么呢?
更新:
测试失败
@Autowired
IntermediaryDaoJpaImpl dao; //this works fine
@Test
public void getIntermediariesTest() {
List<Intermediary> intermediaries = dao.getIntermediaries();
for(Intermediary intermediary : intermediaries) {
System.out.println("Employees: "+intermediary.getEmployees());
assert intermediary.getEmployees() != null;
}
}
道:
@PersistenceContext
private EntityManager entityManager; //this works
public List<Intermediary> getIntermediaries() {
Query query = entityManager.createQuery("select o FROM Intermediary o");
return query.getResultList();
}
的persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="manager1" transaction-type="RESOURCE_LOCAL">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>java:comp/env/jdbc/Datasource</jta-data-source>
<class>com.qbe.asia.ebusiness.admin.intermediary.Intermediary</class>
<class>com.qbe.asia.ebusiness.admin.intermediary.Employee</class>
<properties>
<property name="openjpa.jdbc.DBDictionary" value="db2(batchLimit=0)"/>
<property name="openjpa.Log" value="SQL=TRACE" />
<property name="openjpa.ConnectionFactoryProperties" value="PrettyPrint=true, PrettyPrintLineLength=72" />
<property name="openjpa.RuntimeUnenhancedClasses" value="supported" />
</properties>
</persistence-unit>
</persistence>
答案 0 :(得分:0)
将@JoinTable
注释更改为:
@JoinTable(name="TINT_STAFF",
joinColumns = @JoinColumn(name = "INTERMEDIARY_ID"),
inverseJoinColumns = @JoinColumn(name = "STAFF_ID""))
可能你想做那样的事。