Map Entities to tables with Qi4J

31 views
Skip to first unread message

Hunter

unread,
Dec 28, 2013, 7:14:19 PM12/28/13
to qi4j...@googlegroups.com

Using Qi4j how should I map the properties of Entities to columns of tables of an SQL database?

Is there a way to reuse my JPA annotation configuration?

Niclas Hedhman

unread,
Dec 28, 2013, 11:27:17 PM12/28/13
to Hunter, qi4j...@googlegroups.com

This is something that the community has tried to tackle almost since the inception of Qi4j. The QRM extension was an attempt to create a generic Qi4j-Relational-Mapping, but the rabbit hole quickly becomes a very deep, slippery slope proposition for the generic case. So instead of ending up with something like Hibernate's mess, we decided to stop pretending it was a reasonable thing to do.

Instead, we provided APIs and SPIs into the guts of Qi4j, so that it would be possible to do this on a case-by-case basis, which is easier as many edge cases can be ignored or handled specifically for the project itself.

As for JPA --> If I remember correctly, it depends on naming conventions of methods, a.k.a. getters/setters, and Hibernate's meta data level isn't much easier than working directly with reasonable JDBC abstraction layer such as MyBatis (QRM tried to use this) or Cayenne.

Now that said, before giving you the full answer of what to recommend, you need to provide us with "Why do you need this?". Is it because you rely on using the DB as an integration point between different applications (Not a good idea, but...) ? Is it for reporting? Is it because those tables already exists, if so why can't they be migrated? Why are you willing to sacrifice a lot of simplicity and performance, to maintain the Relation model?

Also, please consider to do a Proof-Of-Concept of your application before trying to tackle the "Map to SQL" problem. Qi4j goes to great lengths to ensure that no persistence implementation details leaks from the SPI to the application, and you should be able to swap in your own "SQL EntityStore" implementation at a later stage, or come to the conclusion that the requirement isn't really that important...

Looking forward to your requirements.

Niclas





On Sun, Dec 29, 2013 at 8:14 AM, Hunter <frederik....@gmail.com> wrote:

Using Qi4j how should I map the properties of Entities to columns of tables of an SQL database?

Is there a way to reuse my JPA annotation configuration?

--
You received this message because you are subscribed to the Google Groups "qi4j-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qi4j-dev+u...@googlegroups.com.
To post to this group, send email to qi4j...@googlegroups.com.
Visit this group at http://groups.google.com/group/qi4j-dev.
For more options, visit https://groups.google.com/groups/opt_out.



--
Niclas Hedhman, Software Developer
河南南路555弄15号1901室。
http://www.qi4j.org - New Energy for Java

I live here; http://tinyurl.com/3xugrbk
I work here; http://tinyurl.com/6a2pl4j
I relax here; http://tinyurl.com/2cgsug

Hunter

unread,
Dec 29, 2013, 5:11:30 AM12/29/13
to qi4j...@googlegroups.com, Hunter, nic...@hedhman.org
As you have correctly presumed , the database already exists and we have a lot of reports using sql queries.
We use an Oracle database and it has a limitation of 30 characters for column name lengths. It helps to keep the database readable if we kan choose the names of the columns and what part to be abbreviated. But I guess you would argue to choose the property names shorter?
We also use a feature of the database called "hiërarchical queries" (not a good idea) that was used in a materialized view. This view is mapped onto a readonly entity. Not sure if this is really relevant in this discussion. :-)

Sometimes queries don't perform and we pass them over to our DBA team. We often get remarks the way JPA transforms jpql into sql and it would be nice to have full control as I understand is the case with Qi4J.
But it would be scary to loose it to the mapping side? Maybe unfairly.


Op zondag 29 december 2013 05:27:17 UTC+1 schreef Niclas Hedhman:

Paul Merlin

unread,
Jan 5, 2014, 7:14:48 AM1/5/14
to qi4j...@googlegroups.com, Hunter
Frederik,


Hunter a écrit :

Using Qi4j how should I map the properties of Entities to columns of tables of an SQL database?

As Niclas already wrote, there's no built-in way to map Entities
to existing SQL tables. What Qi4j SQL support provide is easy JDBC
configuration and connection pooling plus a simple Key-Value-Like
EntityStore and an Index/Query engine that work on SQL databases.

The SQL Support Sample show how to use all of this.

As your database already exist you could write your own EntityStore
and Index/Query engine but this would be tedious and fragile work as
it would be tied to your domain.

Is there a way to reuse my JPA annotation configuration?

Nothing stops you from using Qi4j, except persistence stuff,
alongside/inside your JPA application.

Cheers

/Paul

Reply all
Reply to author
Forward
0 new messages