我有這個數據模型:的EclipseLink MySQL的左連接錯誤:未知列
AbstractEntity (abstract, @MappedSuperClass)
|
+---- Subject (abstract, @Entity, joined)
| |
| +---- Person (@Entity)
| |
| +---- ...
|
+---- Metadata (abstract, @Entity, joined)
|
+---- ...
實現了:
@MappedSuperclass
public abstract class AbstractEntity implements Serializable
{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(nullable = false)
protected Long id;
@Version
protected Integer version;
...
}
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Subject extends AbstractEntity
{
@ManyToOne
@JoinColumn(name = "PROFILE_ID")
protected Profile profile;
@ElementCollection
@CollectionTable(name = "SUBJECT_RIGHTS", joinColumns = @JoinColumn(name = "OWNER_ID"))
@Column(name = "CODE")
protected Set<String> rightSet = new HashSet<String>();
@Transient
public abstract String getTitle();
...
}
@Entity
public class Person extends AbstractEntity
{
@NotBlank
private String firstName;
@NotBlank
private String lastName;
...
}
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Metadata extends AbstractEntity
{
@ElementCollection
@CollectionTable(name = "METADATA_PREFERENCE", joinColumns = @JoinColumn(name = "METADATA_ID"))
@MapKeyJoinColumn(name = "PERSON_ID", nullable = false)
@Enumerated(EnumType.STRING)
@Column(name = "PREFERENCE", nullable = false)
protected Map<Person, PreferenceType> preferenceMap = new LinkedHashMap<Person, PreferenceType>();
...
}
,我試圖執行這個查詢:
select m.id from Metadata m left join m.preferenceMap p [where not important]
和eclipselink生成此SQL:
SELECT t0.ID FROM METADATA t0 LEFT OUTER JOIN METADATA_PREFERENCE t3 ON ((t3.METADATA_ID = t0.ID) AND (t1.ID = t3.PERSON_ID)), PERSON t2, SUBJECT t1 [where not important]
但此查詢產生的異常:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 't1.ID' in 'on clause'
我知道MySQL的加入優先級,所以我需要的EclipseLink以這種方式重寫查詢:
SELECT t0.ID FROM (METADATA t0, SUBJECT t1) LEFT OUTER JOIN METADATA_PREFERENCE t3 ON ((t3.METADATA_ID = t0.ID) AND (t1.ID = t3.PERSON_ID)), PERSON t2 [where not important]
如何做到這一點? ??
但是我使用:
mysql:
+-------------------------+------------------------------+
| Variable_name | Value |
+-------------------------+------------------------------+
| innodb_version | 1.1.7 |
| protocol_version | 10 |
| slave_type_conversions | |
| version | 5.5.13-log |
| version_comment | MySQL Community Server (GPL) |
| version_compile_machine | x86 |
| version_compile_os | Win64 |
+-------------------------+------------------------------+
eclipselink:
Eclipse Persistence Services - 2.4.1.v20121003-ad44345
,這是persistence.xml中
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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">
<persistence-unit name="prime" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/prime</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="eclipselink.target-database" value="MySQL"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/prime"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="password"/>
</properties>
</persistence-unit>
</persistence>
我正在使用最新的修補程序。 我喜歡這種映射,以方便JSF控制器操作,我目前使用子查詢作爲解決方法(內部連接可以工作:))。然而,我正在將此日誌記錄到eclipselink。 thx! –