You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Igor Drobiazko <ig...@gmail.com> on 2011/07/12 22:56:14 UTC

JPA: Auto-scanning classpath

The recent discussion on the user's list on JPA integration is quite
interesting. The question is whether Tapestry should automatically add
entities found anywhere on the classpath to the EntityManagers. Here is the
link to the discussion:

http://markmail.org/message/wb3iu3adpotbephh

Currently it works as:

1) if there is only a single persistence unit configured, only entities from
app's entities package are automatically added to the EntityManager. This
conforms to behavior of the Hibenrate library and works out of the box.
However, this conflicts with the JPA specification in some way. JPA
specification says that <exclude-unlisted-classes> controls whether
auto-scanning should be done or not. Currently, this element is ignored in
Tapestry.

2) If multiple persistence units are configured, no auto-scanning happens.
None of the entities is added to any EntityManager. When discovering an
entity class on the classpath, Tapestry can't know to which EntityManager it
belongs. It also doesn't make sense to add all the entities to all the
EntityManagers. So, when using multiple persistence unit, the user needs to
add the entities explicitly.

Any feedback? Ideas?

-- 
Best regards,

Igor Drobiazko
http://tapestry5.de

Re: JPA: Auto-scanning classpath

Posted by Kalle Korhonen <ka...@gmail.com>.
On Wed, Jul 13, 2011 at 9:34 AM, Lenny Primak <lp...@hope.nyc.ny.us> wrote:
> After sleeping on this I have an even simpler suggestion. Just auto-scan the .../entities.${persistenceUnit}
> pah fo it's own entities by default and update package contributor to return a map of PUs to paths so it's easy to customize.
> I.e default search path com.xxx.app.entities.PU

Sounds pretty reasonable to me.

Kalle

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org


Re: JPA: Auto-scanning classpath

Posted by Lenny Primak <lp...@hope.nyc.ny.us>.
I am confused. The way I understand your post is that you want to make even harder for the single persistent user people and do nothing for multiple persistent unit case?
I think I am misunderstanding your post. 
I think any solution should pass the "it works out of the box" test. 
Consider a scenario that someone adds a second persistent unit into persistent.XML file. 
Now all of the sudden everything breaks. 
I think it's such a common problem ( both single and multiple PUs ) that
This should be made braindead simple. 


On Jul 13, 2011, at 5:12 PM, Igor Drobiazko <ig...@gmail.com> wrote:

> At a first glance I liked the idea, but the more I think about it the less
> it sounds reasonable to me. Encoding persistence unit name as a sub-package
> provides more confusion than benefits. First of all because it limits you in
> naming your persistence units. As per JPA spec a unit's name is a string.
> So, you are free to use names like "foo-bar" or "1unit" which we would need
> to encode into valid Java package names. This will be confusing.  Another
> objection is that renaming unit name you would need to rename your
> packages.
> 
> I think I'll do it as follows:
> 
> 1) Single persistence unit:
> 
> 1.1) The most of the users will be having only a single persistence unit.
> For such users we need to provide a solution which is compatible with the
> JPA spec. So,we allow autoscanning of the classpath and don't auto-include
> entities from root-package.entities.
> 
> 1.2) For those of us, who loves to place the entities
> into root-package.entities, we could provide a symbol like
> "jpa-compatibility-mode" which is true by default. Having
> jpa-compatibility-mode=true
> results in behavior described in 1.1. If the mode is set to false,
> auto-scanning is switched off and the entities
> from root-package.entities are added automatically.
> 
> 2) Multiple persistence units
> 
> In this case we don't include any of the entities automaticall. The user is
> responsible to add the entities to the entity managers manually as only
> he/she knows which entity belongs to which manager.
> 
> I think this solution provides the lowest confusion rate as the most
> frequent use case just works out of the box.
> 
> On Wed, Jul 13, 2011 at 6:34 PM, Lenny Primak <lp...@hope.nyc.ny.us>wrote:
> 
>> After sleeping on this I have an even simpler suggestion. Just auto-scan
>> the .../entities.${persistenceUnit}
>> pah fo it's own entities by default and update package contributor to
>> return a map of PUs to paths so it's easy to customize.
>> 
>> I.e default search path com.xxx.app.entities.PU
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: dev-help@tapestry.apache.org
>> 
>> 
> 
> 
> -- 
> Best regards,
> 
> Igor Drobiazko
> http://tapestry5.de

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org


Re: JPA: Auto-scanning classpath

Posted by Igor Drobiazko <ig...@gmail.com>.
At a first glance I liked the idea, but the more I think about it the less
it sounds reasonable to me. Encoding persistence unit name as a sub-package
provides more confusion than benefits. First of all because it limits you in
naming your persistence units. As per JPA spec a unit's name is a string.
So, you are free to use names like "foo-bar" or "1unit" which we would need
to encode into valid Java package names. This will be confusing.  Another
objection is that renaming unit name you would need to rename your
packages.

I think I'll do it as follows:

1) Single persistence unit:

1.1) The most of the users will be having only a single persistence unit.
For such users we need to provide a solution which is compatible with the
JPA spec. So,we allow autoscanning of the classpath and don't auto-include
entities from root-package.entities.

1.2) For those of us, who loves to place the entities
into root-package.entities, we could provide a symbol like
"jpa-compatibility-mode" which is true by default. Having
jpa-compatibility-mode=true
 results in behavior described in 1.1. If the mode is set to false,
auto-scanning is switched off and the entities
from root-package.entities are added automatically.

2) Multiple persistence units

In this case we don't include any of the entities automaticall. The user is
responsible to add the entities to the entity managers manually as only
he/she knows which entity belongs to which manager.

I think this solution provides the lowest confusion rate as the most
frequent use case just works out of the box.

On Wed, Jul 13, 2011 at 6:34 PM, Lenny Primak <lp...@hope.nyc.ny.us>wrote:

> After sleeping on this I have an even simpler suggestion. Just auto-scan
> the .../entities.${persistenceUnit}
> pah fo it's own entities by default and update package contributor to
> return a map of PUs to paths so it's easy to customize.
>
> I.e default search path com.xxx.app.entities.PU
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: dev-help@tapestry.apache.org
>
>


-- 
Best regards,

Igor Drobiazko
http://tapestry5.de

Re: JPA: Auto-scanning classpath

Posted by Lenny Primak <lp...@hope.nyc.ny.us>.
After sleeping on this I have an even simpler suggestion. Just auto-scan the .../entities.${persistenceUnit}
pah fo it's own entities by default and update package contributor to return a map of PUs to paths so it's easy to customize. 

I.e default search path com.xxx.app.entities.PU


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org


Re: JPA: Auto-scanning classpath

Posted by Taha Hafeez <ta...@gmail.com>.
Hi Igor,

Thanks for the information. Googled a bit and found this
http://static.springsource.org/spring/docs/2.0.x/reference/orm.html#orm-jpa

There is a section "12.6.1.4. Dealing with multiple persistence units" which
talks about spring's solution to the problem

regards
Taha


On Wed, Jul 13, 2011 at 6:16 PM, Igor Drobiazko <ig...@gmail.com>wrote:

> Hi Tawus,
>
> this is a bit different story because Hibernate doesn't scan the classpath.
> As a Hibernate user you need to configure your entities manually. So, you
> would never expect the entities to be added automatically. Obviously, JPA
> users do. But I still think that in case of multiple persistence units no
> classpath scanning should happen.
>
> Thank you
>
> On Wed, Jul 13, 2011 at 2:34 AM, Taha Hafeez <tawus.tapestry@gmail.com
> >wrote:
>
> > Hi Igor
> >
> > I have a multiple-database support for hibernate in tawus-core. What I do
> > to
> > handle this situation is to allow users to specify a configuration for
> each
> > sessionfactory and that configuration takes a list of package names as
> > argument. The SessionFactorySource creates a SessionFactory for each
> > configuration, scans the given packages, adds the classes in the given
> > package names to the session factory.
> >
> >
> >
> https://github.com/tawus/tawus/blob/master/tawus-hibernate/src/main/java/com/googlecode/tawus/hibernate/internal/services/SessionFactorySourceImpl.java
> >
> >
> >
> https://github.com/tawus/tawus/blob/master/tawus-hibernate/src/main/java/com/googlecode/tawus/hibernate/services/SessionFactoryConfiguration.java
> >
> > Which classes to add can be setup by a filter
> >
> > regards
> > Taha
> >
> >
> > On Wed, Jul 13, 2011 at 2:30 AM, Lenny Primak <lprimak@hope.nyc.ny.us
> > >wrote:
> >
> > > Since I was the 'victim' of all of this, and worked through a solution,
> > > My suggestion wold be to contribute some sort of a configuration map
> > > of persistence units to package names, maybe a one-line of code,
> > > an annotation of some sort.
> > >
> > > On Jul 12, 2011, at 4:56 PM, Igor Drobiazko wrote:
> > >
> > > > The recent discussion on the user's list on JPA integration is quite
> > > > interesting. The question is whether Tapestry should automatically
> add
> > > > entities found anywhere on the classpath to the EntityManagers. Here
> is
> > > the
> > > > link to the discussion:
> > > >
> > > > http://markmail.org/message/wb3iu3adpotbephh
> > > >
> > > > Currently it works as:
> > > >
> > > > 1) if there is only a single persistence unit configured, only
> entities
> > > from
> > > > app's entities package are automatically added to the EntityManager.
> > This
> > > > conforms to behavior of the Hibenrate library and works out of the
> box.
> > > > However, this conflicts with the JPA specification in some way. JPA
> > > > specification says that <exclude-unlisted-classes> controls whether
> > > > auto-scanning should be done or not. Currently, this element is
> ignored
> > > in
> > > > Tapestry.
> > > >
> > > > 2) If multiple persistence units are configured, no auto-scanning
> > > happens.
> > > > None of the entities is added to any EntityManager. When discovering
> an
> > > > entity class on the classpath, Tapestry can't know to which
> > EntityManager
> > > it
> > > > belongs. It also doesn't make sense to add all the entities to all
> the
> > > > EntityManagers. So, when using multiple persistence unit, the user
> > needs
> > > to
> > > > add the entities explicitly.
> > > >
> > > > Any feedback? Ideas?
> > > >
> > > > --
> > > > Best regards,
> > > >
> > > > Igor Drobiazko
> > > > http://tapestry5.de
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
> > > For additional commands, e-mail: dev-help@tapestry.apache.org
> > >
> > >
> >
>
>
>
> --
> Best regards,
>
> Igor Drobiazko
> http://tapestry5.de
>

Re: JPA: Auto-scanning classpath

Posted by Igor Drobiazko <ig...@gmail.com>.
Hi Tawus,

this is a bit different story because Hibernate doesn't scan the classpath.
As a Hibernate user you need to configure your entities manually. So, you
would never expect the entities to be added automatically. Obviously, JPA
users do. But I still think that in case of multiple persistence units no
classpath scanning should happen.

Thank you

On Wed, Jul 13, 2011 at 2:34 AM, Taha Hafeez <ta...@gmail.com>wrote:

> Hi Igor
>
> I have a multiple-database support for hibernate in tawus-core. What I do
> to
> handle this situation is to allow users to specify a configuration for each
> sessionfactory and that configuration takes a list of package names as
> argument. The SessionFactorySource creates a SessionFactory for each
> configuration, scans the given packages, adds the classes in the given
> package names to the session factory.
>
>
> https://github.com/tawus/tawus/blob/master/tawus-hibernate/src/main/java/com/googlecode/tawus/hibernate/internal/services/SessionFactorySourceImpl.java
>
>
> https://github.com/tawus/tawus/blob/master/tawus-hibernate/src/main/java/com/googlecode/tawus/hibernate/services/SessionFactoryConfiguration.java
>
> Which classes to add can be setup by a filter
>
> regards
> Taha
>
>
> On Wed, Jul 13, 2011 at 2:30 AM, Lenny Primak <lprimak@hope.nyc.ny.us
> >wrote:
>
> > Since I was the 'victim' of all of this, and worked through a solution,
> > My suggestion wold be to contribute some sort of a configuration map
> > of persistence units to package names, maybe a one-line of code,
> > an annotation of some sort.
> >
> > On Jul 12, 2011, at 4:56 PM, Igor Drobiazko wrote:
> >
> > > The recent discussion on the user's list on JPA integration is quite
> > > interesting. The question is whether Tapestry should automatically add
> > > entities found anywhere on the classpath to the EntityManagers. Here is
> > the
> > > link to the discussion:
> > >
> > > http://markmail.org/message/wb3iu3adpotbephh
> > >
> > > Currently it works as:
> > >
> > > 1) if there is only a single persistence unit configured, only entities
> > from
> > > app's entities package are automatically added to the EntityManager.
> This
> > > conforms to behavior of the Hibenrate library and works out of the box.
> > > However, this conflicts with the JPA specification in some way. JPA
> > > specification says that <exclude-unlisted-classes> controls whether
> > > auto-scanning should be done or not. Currently, this element is ignored
> > in
> > > Tapestry.
> > >
> > > 2) If multiple persistence units are configured, no auto-scanning
> > happens.
> > > None of the entities is added to any EntityManager. When discovering an
> > > entity class on the classpath, Tapestry can't know to which
> EntityManager
> > it
> > > belongs. It also doesn't make sense to add all the entities to all the
> > > EntityManagers. So, when using multiple persistence unit, the user
> needs
> > to
> > > add the entities explicitly.
> > >
> > > Any feedback? Ideas?
> > >
> > > --
> > > Best regards,
> > >
> > > Igor Drobiazko
> > > http://tapestry5.de
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: dev-help@tapestry.apache.org
> >
> >
>



-- 
Best regards,

Igor Drobiazko
http://tapestry5.de

Re: JPA: Auto-scanning classpath

Posted by Taha Hafeez <ta...@gmail.com>.
Hi Igor

I have a multiple-database support for hibernate in tawus-core. What I do to
handle this situation is to allow users to specify a configuration for each
sessionfactory and that configuration takes a list of package names as
argument. The SessionFactorySource creates a SessionFactory for each
configuration, scans the given packages, adds the classes in the given
package names to the session factory.

https://github.com/tawus/tawus/blob/master/tawus-hibernate/src/main/java/com/googlecode/tawus/hibernate/internal/services/SessionFactorySourceImpl.java

https://github.com/tawus/tawus/blob/master/tawus-hibernate/src/main/java/com/googlecode/tawus/hibernate/services/SessionFactoryConfiguration.java

Which classes to add can be setup by a filter

regards
Taha


On Wed, Jul 13, 2011 at 2:30 AM, Lenny Primak <lp...@hope.nyc.ny.us>wrote:

> Since I was the 'victim' of all of this, and worked through a solution,
> My suggestion wold be to contribute some sort of a configuration map
> of persistence units to package names, maybe a one-line of code,
> an annotation of some sort.
>
> On Jul 12, 2011, at 4:56 PM, Igor Drobiazko wrote:
>
> > The recent discussion on the user's list on JPA integration is quite
> > interesting. The question is whether Tapestry should automatically add
> > entities found anywhere on the classpath to the EntityManagers. Here is
> the
> > link to the discussion:
> >
> > http://markmail.org/message/wb3iu3adpotbephh
> >
> > Currently it works as:
> >
> > 1) if there is only a single persistence unit configured, only entities
> from
> > app's entities package are automatically added to the EntityManager. This
> > conforms to behavior of the Hibenrate library and works out of the box.
> > However, this conflicts with the JPA specification in some way. JPA
> > specification says that <exclude-unlisted-classes> controls whether
> > auto-scanning should be done or not. Currently, this element is ignored
> in
> > Tapestry.
> >
> > 2) If multiple persistence units are configured, no auto-scanning
> happens.
> > None of the entities is added to any EntityManager. When discovering an
> > entity class on the classpath, Tapestry can't know to which EntityManager
> it
> > belongs. It also doesn't make sense to add all the entities to all the
> > EntityManagers. So, when using multiple persistence unit, the user needs
> to
> > add the entities explicitly.
> >
> > Any feedback? Ideas?
> >
> > --
> > Best regards,
> >
> > Igor Drobiazko
> > http://tapestry5.de
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: dev-help@tapestry.apache.org
>
>

Re: JPA: Auto-scanning classpath

Posted by Lenny Primak <lp...@hope.nyc.ny.us>.
Since I was the 'victim' of all of this, and worked through a solution,
My suggestion wold be to contribute some sort of a configuration map
of persistence units to package names, maybe a one-line of code,
an annotation of some sort.

On Jul 12, 2011, at 4:56 PM, Igor Drobiazko wrote:

> The recent discussion on the user's list on JPA integration is quite
> interesting. The question is whether Tapestry should automatically add
> entities found anywhere on the classpath to the EntityManagers. Here is the
> link to the discussion:
> 
> http://markmail.org/message/wb3iu3adpotbephh
> 
> Currently it works as:
> 
> 1) if there is only a single persistence unit configured, only entities from
> app's entities package are automatically added to the EntityManager. This
> conforms to behavior of the Hibenrate library and works out of the box.
> However, this conflicts with the JPA specification in some way. JPA
> specification says that <exclude-unlisted-classes> controls whether
> auto-scanning should be done or not. Currently, this element is ignored in
> Tapestry.
> 
> 2) If multiple persistence units are configured, no auto-scanning happens.
> None of the entities is added to any EntityManager. When discovering an
> entity class on the classpath, Tapestry can't know to which EntityManager it
> belongs. It also doesn't make sense to add all the entities to all the
> EntityManagers. So, when using multiple persistence unit, the user needs to
> add the entities explicitly.
> 
> Any feedback? Ideas?
> 
> -- 
> Best regards,
> 
> Igor Drobiazko
> http://tapestry5.de


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org