Greetings eclipseLinks fellows
I suppose I've found bug on eclipseLink MT and looking for work-around, how can I make things work. I will really glad, if you find some mistake or missing configuration on my code. Looking forward for yours suggestions.
I was playing with different combination of entities @annotation, but things went only worst.
I've used JPA Single inheritance strategy and MT table per tenant.
Enviroment:
GlassFish Server Open Source Edition 4.0 (build 89)
Eclipse Persistence Services - 2.5.0.v20130507-3faac2b
persistence.xml
...
<persistence-unit name="NewPersistenceUnit" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/mySqlTest</jta-data-source>
<properties>
<property name="eclipselink.logging.level" value="INFO"/>
</properties>
</persistence-unit>
...
Entities
@Entity
@Inheritance( strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "contact_type")
@Multitenant(MultitenantType.TABLE_PER_TENANT)
@TenantTableDiscriminator(type= TenantTableDiscriminatorType.SCHEMA)
public class Contact {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column
private String base;
...
}
@Entity
@Multitenant(MultitenantType.TABLE_PER_TENANT)
@TenantTableDiscriminator(type= TenantTableDiscriminatorType.SCHEMA)
@DiscriminatorValue("PERSON")
public class Person extends Contact {
@Column
private String message;
...
}
Persist logic
@Stateless
public class PersonEJB {
@PersistenceUnit
EntityManagerFactory emf;
public void doIt() {
Map props = new HashMap();
props.put(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, "test");
props.put(PersistenceUnitProperties.MULTITENANT_SHARED_EMF, true);
EntityManager em = emf.createEntityManager(props);
Person p = new Person();
p.setMessage("I'm just trying");
p.setBase("I'm just base attribute");
em.persist( p);
}
}
Exception:
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'MESSAGE' in 'field list'
Error Code: 1054
Call: INSERT INTO test.CONTACT (BASE, MESSAGE, contact_type) VALUES (?, ?, ?)
bind => [3 parameters bound]
Query: InsertObjectQuery(sk.Person@1273b31f)
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:331)
em.createQuery("SELECT p FROM Person p WHERE p.base = 'hi' ", Person.class).getResultList();
Exception:
Caused by: java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Problem compiling [SELECT p FROM Person p WHERE p.base = 'hi' ].
[29, 35] The state field path 'p.base' cannot be resolved to a valid type.
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1585)
em.createQuery("SELECT p FROM Person p", Person.class).getResultList();
Exception:
Caused by: Exception [EclipseLink-6121] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.QueryException
Exception Description: The query has not been defined correctly, the expression builder is missing. For sub and parallel queries ensure the queries builder is always on the left.
Query: ReadAllQuery(referenceClass=Person jpql="SELECT p FROM Person p")
at org.eclipse.persistence.exceptions.QueryException.invalidBuilderInQuery(QueryException.java:683)