Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Multitenancy & single table inheritance(Queries work directly to the base entity and ignore child entity or oposite)
Multitenancy & single table inheritance [message #1385252] Thu, 05 June 2014 08:09 Go to next message
Viliam Kois is currently offline Viliam KoisFriend
Messages: 6
Registered: March 2014
Junior Member
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)
Re: Multitenancy & single table inheritance [message #1385439 is a reply to message #1385252] Fri, 06 June 2014 12:48 Go to previous messageGo to next message
Viliam Kois is currently offline Viliam KoisFriend
Messages: 6
Registered: March 2014
Junior Member
On eclipselink-2.5.2.v20140402-e6e1220

It does work Smile
Re: Multitenancy & single table inheritance [message #1385441 is a reply to message #1385439] Fri, 06 June 2014 12:59 Go to previous messageGo to next message
Viliam Kois is currently offline Viliam KoisFriend
Messages: 6
Registered: March 2014
Junior Member
But there is still problem with Criteria API on this inheritance type.

I had tried on eclipselink-2.6.0.v20140531-afd7834 too, but without any success.
Re: Multitenancy & single table inheritance [message #1386376 is a reply to message #1385441] Tue, 17 June 2014 08:34 Go to previous message
Viliam Kois is currently offline Viliam KoisFriend
Messages: 6
Registered: March 2014
Junior Member
It looks, when you use annotation processor, then Criteria API works too.
Previous Topic:EL QBE JPA2
Next Topic:Unmapped attributes of superclass have wrong value
Goto Forum:
  


Current Time: Tue Apr 23 16:23:13 GMT 2024

Powered by FUDForum. Page generated in 0.03793 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top