672329 members! Sign up to stay informed.

Sponsored Links


Resources

Enterprise Java
Research Library

Get Java white papers, product information, case studies and webcasts

News News News Messages: 47 Messages: 47 Messages: 47 Printer friendly Printer friendly Printer friendly Post reply Post reply Post reply XML XML XML

Getting started with EJB 3.0 persistence out-of-container

Posted by: Joseph Ottinger on December 28, 2005 DIGG
Lucas Jellema has written an article called "Getting Started with EJB 3.0 Persistence out-of-container using the Reference Implementation (GlassFish)," which shows step-by-step how you can use the reference implementation to persist data with EJB3.0 persistence, including a service class and a data model.

It's good to see people documenting their experiences with the various containers; now we need to start seeing use cases and things that don't work with EJB3, so we can start building guidelines for when it should or shouldn't be used.

Threaded replies

·  Getting started with EJB 3.0 persistence out-of-container by Joseph Ottinger on Wed Dec 28 09:30:33 EST 2005
  ·  Getting started with EJB 3.0 persistence out-of-container by Gavin King on Wed Dec 28 10:33:36 EST 2005
    ·  Hahaha by Joseph Ottinger on Wed Dec 28 10:39:12 EST 2005
      ·  Hahaha by Gavin King on Wed Dec 28 10:45:41 EST 2005
        ·  What I find most funny... by David Ward on Wed Dec 28 13:59:51 EST 2005
      ·  Hahaha by Abbul Thammineedi` on Wed Dec 28 23:35:42 EST 2005
    ·  Getting started with EJB 3.0 persistence out-of-container by Rashid Jilani on Wed Dec 28 12:01:00 EST 2005
      ·  EJB3 entities are very different by Patrick Linskey on Thu Dec 29 01:48:10 EST 2005
        ·  EJB3 entities are very different by Rashid Jilani on Thu Dec 29 10:53:21 EST 2005
          ·  Afterwards by Werner Punz on Thu Dec 29 12:51:08 EST 2005
            ·  Afterwards by Steve Zara on Thu Dec 29 14:23:03 EST 2005
            ·  Afterwards by Rashid Jilani on Thu Dec 29 15:28:31 EST 2005
              ·  Afterwards by Werner Punz on Thu Dec 29 15:45:19 EST 2005
                ·  Afterwards by Rashid Jilani on Thu Dec 29 16:47:49 EST 2005
    ·  Well by Werner Punz on Wed Dec 28 12:49:46 EST 2005
      ·  Gavin' by Dan Hinojosa on Wed Dec 28 18:49:41 EST 2005
    ·  Getting started with EJB 3.0 persistence out-of-container by Kristof Jozsa on Wed Dec 28 16:27:23 EST 2005
    ·  Getting started with EJB 3.0 persistence out-of-container by Jan de Jonge on Thu Dec 29 19:16:25 EST 2005
  ·  I still LOVE JDO. by maria maria on Wed Dec 28 11:07:57 EST 2005
  ·  Getting started with EJB 3.0 persistence out-of-container by Jacob Hookom on Wed Dec 28 12:08:20 EST 2005
  ·  Getting started with EJB 3.0 persistence out-of-container by Sven Bauer on Wed Dec 28 12:39:06 EST 2005
    ·  Nifty! by vc vccvx cvxcvcvx on Wed Dec 28 12:54:33 EST 2005
      ·  Nifty! by Steve Zara on Wed Dec 28 13:06:14 EST 2005
  ·  Getting started with EJB 3.0 persistence out-of-container by Marius Danciu on Wed Dec 28 13:07:20 EST 2005
    ·  Getting started with EJB 3.0 persistence out-of-container by Patrick Linskey on Thu Dec 29 01:45:39 EST 2005
      ·  Getting started with EJB 3.0 persistence out-of-container by Steve Zara on Thu Dec 29 06:26:09 EST 2005
      ·  Getting started with EJB 3.0 persistence out-of-container by Marius Danciu on Thu Dec 29 06:45:08 EST 2005
        ·  Getting started with EJB 3.0 persistence out-of-container by Alex Vasseur on Thu Dec 29 07:42:50 EST 2005
          ·  Getting started with EJB 3.0 persistence out-of-container by Marius Danciu on Thu Dec 29 08:49:57 EST 2005
        ·  Getting started with EJB 3.0 persistence out-of-container by Emmanuel Bernard on Thu Dec 29 09:05:11 EST 2005
          ·  Getting started with EJB 3.0 persistence out-of-container by Marius Danciu on Thu Dec 29 09:15:26 EST 2005
          ·  Getting started with EJB 3.0 persistence out-of-container by Davide Baroncelli on Thu Dec 29 10:32:04 EST 2005
  ·  Getting started with EJB 3.0 persistence out-of-container by Sam. A on Wed Dec 28 17:13:25 EST 2005
  ·  Getting started with EJB 3.0 persistence out-of-container by ketan padia on Wed Dec 28 18:16:04 EST 2005
  ·  Getting started with EJB 3.0 persistence out-of-container by Shahzad Masud on Thu Dec 29 01:52:27 EST 2005
  ·  EJB 3.0 persistence by Randy Schnier on Thu Dec 29 12:57:52 EST 2005
  ·  Annotations by Rob Rudin on Thu Dec 29 22:05:06 EST 2005
    ·  Annotations by Sahoo Sanjeeb on Fri Dec 30 03:20:31 EST 2005
      ·  Another advantage of annotations by Werner Punz on Fri Dec 30 04:28:47 EST 2005
        ·  Another advantage of annotations by Henrique Steckelberg on Fri Dec 30 06:54:01 EST 2005
    ·  Annotations by Artur Karazniewicz on Fri Dec 30 06:54:31 EST 2005
      ·  adjust your though patterns by Werner Punz on Fri Dec 30 06:59:53 EST 2005
        ·  adjust your though patterns by Artur Karazniewicz on Fri Dec 30 08:02:35 EST 2005
          ·  adjust your though patterns by Emmanuel Bernard on Fri Dec 30 09:16:15 EST 2005
            ·  adjust your though patterns by Artur Karazniewicz on Fri Dec 30 09:59:08 EST 2005
      ·  Annotations by Gavin King on Fri Dec 30 20:54:49 EST 2005
        ·  Annotations by Juozas Baliuka on Sat Dec 31 03:26:40 EST 2005
  ·  Getting started with EJB 3.0 persistence out-of-container by Sreenath V on Fri Dec 30 12:02:52 EST 2005
  Message #195368 Post reply Post reply Post reply Go to top Go to top Go to top

Getting started with EJB 3.0 persistence out-of-container

Posted by: Gavin King on December 28, 2005 in response to Message #195365
"EJB 3.0 persistence out-of-container"

WTF??? You can do that???

But I remember more than one TSS thread from a while back where people so much more knowledgeable and intelligent than I were explaining to me how that would never be possible!

What's going on here? You mean I can't believe everything I read on TSS anymore??

My world is crumbling around me.

  Message #195369 Post reply Post reply Post reply Go to top Go to top Go to top

Hahaha

Posted by: Joseph Ottinger on December 28, 2005 in response to Message #195368
Gavin, you're quite the kidder, ain'tcha! :)

  Message #195370 Post reply Post reply Post reply Go to top Go to top Go to top

Hahaha

Posted by: Gavin King on December 28, 2005 in response to Message #195369
The jokes. Always with the jokes.

  Message #195375 Post reply Post reply Post reply Go to top Go to top Go to top

I still LOVE JDO.

Posted by: maria maria on December 28, 2005 in response to Message #195365
I still LOVE JDO.
I'm sorry, but I find JDO is simpler and Better than EJB3.

  Message #195380 Post reply Post reply Post reply Go to top Go to top Go to top

Getting started with EJB 3.0 persistence out-of-container

Posted by: Rashid Jilani on December 28, 2005 in response to Message #195368
"EJB 3.0 persistence out-of-container"WTF??? You can do that???But I remember more than one TSS thread from a while back where people so much more knowledgeable and intelligent than I were explaining to me how that would never be possible!What's going on here? You mean I can't believe everything I read on TSS anymore??My world is crumbling around me.

People have been criticizing EntityBean since it's inception. The main reason was you don't want to corrupt your domain/entity obejcts with some funny EJB interfaces. Besides this your domain object should not be constraint on any kind of container. Go and check the very early posts of serverside.com era. I am bit amaze what kind of people you have been arguing with lately.

  Message #195381 Post reply Post reply Post reply Go to top Go to top Go to top

Getting started with EJB 3.0 persistence out-of-container

Posted by: Jacob Hookom on December 28, 2005 in response to Message #195365
While this capability is great, I really think the pursuing point from all vendors is a renewed 'out of the box' feature set with JSE 5. The EJB 3 spec is 'the new POJO'. With built-in support in all containers, you will probably see a rebirth of frameworks that piggy back on on EJB's interceptor stack and event model with simple annotations.

  Message #195385 Post reply Post reply Post reply Go to top Go to top Go to top

Getting started with EJB 3.0 persistence out-of-container

Posted by: Sven Bauer on December 28, 2005 in response to Message #195365
Again this "container"-thing...

I think in times where most of the so called "containers" implement their functionality using some sort of AOP-stuff, it is complete nonsense to make this distinction of "in container" and "out-of-container" ...

  Message #195387 Post reply Post reply Post reply Go to top Go to top Go to top

Well

Posted by: Werner Punz on December 28, 2005 in response to Message #195368
in almost every EJB3 related topic at least one or two posters basically mention that you do not need a container for ejb3 persistence ;-)

  Message #195388 Post reply Post reply Post reply Go to top Go to top Go to top

Nifty!

Posted by: vc vccvx cvxcvcvx on December 28, 2005 in response to Message #195385
Wow, that's pretty nifty... It's nice to know we can develop STANDARDS-based J2SE ORM solution with EJB 3.0... Can't wait!

  Message #195390 Post reply Post reply Post reply Go to top Go to top Go to top

Nifty!

Posted by: Steve Zara on December 28, 2005 in response to Message #195388
Wow, that's pretty nifty... It's nice to know we can develop STANDARDS-based J2SE ORM solution with EJB 3.0... Can't wait!

You have been able to do this for years with JDO, although now with the JDO 2.0 and EJB 3.0 standards things have certainly improved.

  Message #195391 Post reply Post reply Post reply Go to top Go to top Go to top

Getting started with EJB 3.0 persistence out-of-container

Posted by: Marius Danciu on December 28, 2005 in response to Message #195365
Well, it is nothing spectacular that entity beans can be used now outside of an ejb container: thanks to EntityManager ;) What I think is really valuable is that we finally have a standard and lightweight O/R mapping mechanism, hence application will not be coupled with proprietary frameworks (which can evolve in their own directions) but everything is abstracted by a standard.

Of course it really depends how providers are implementing the specs. Depending of the underlying mechanism that provider is doing to proxy the entity-bean can have a huge impact of the application performance. Remember that EJB 3.0 annotations have RetentionPolicy set to RUNTIME which means that reflection is used in there. What I would be interested to know is if provider is using dynamic proxies (loadtime weaving style which I would prefer because it performs qute well - or it should ) or plain reflection using java Proxy or something similat.

All we have to do now is wait for verdors to provide mature implementations of the specs (hopefully we'll have a lot of vendors to choose :D).

  Message #195397 Post reply Post reply Post reply Go to top Go to top Go to top

What I find most funny...

Posted by: David Ward on December 28, 2005 in response to Message #195370
...is the people who poke fun at TSS and its worth seem to be the most avid readers and posters. :)

  Message #195402 Post reply Post reply Post reply Go to top Go to top Go to top

Getting started with EJB 3.0 persistence out-of-container

Posted by: Kristof Jozsa on December 28, 2005 in response to Message #195368
Got questions? Contact sales@jboss.com!

Soz man, hope you can take it lightly ;)

  Message #195405 Post reply Post reply Post reply Go to top Go to top Go to top

Getting started with EJB 3.0 persistence out-of-container

Posted by: Sam. A on December 28, 2005 in response to Message #195365
Tried to compile and run the app. Got NPE the first time since in persistence.xml xmlns="http://java.sun.com/xml/ns/persistence" is not a valid url. Removed the the xmlns from the file and tried again. Got No Persistence provider for EntityManager named pu1. Used the last promoted build.

  Message #195408 Post reply Post reply Post reply Go to top Go to top Go to top

Getting started with EJB 3.0 persistence out-of-container

Posted by: ketan padia on December 28, 2005 in response to Message #195365
check out Hibernate EntityManager

  Message #195409 Post reply Post reply Post reply Go to top Go to top Go to top

Gavin'

Posted by: Dan Hinojosa on December 28, 2005 in response to Message #195387
http://www.javapolis.com/confluence/display/JP04/Gavin+King

  Message #195418 Post reply Post reply Post reply Go to top Go to top Go to top

Hahaha

Posted by: Abbul Thammineedi` on December 28, 2005 in response to Message #195369
What goes around, comes around. Has it ever not? So next time, watch what your INTELLIGENT heads spew from your mouth's. Better shut up and just put up.

  Message #195420 Post reply Post reply Post reply Go to top Go to top Go to top

Getting started with EJB 3.0 persistence out-of-container

Posted by: Patrick Linskey on December 29, 2005 in response to Message #195391
Remember that EJB 3.0 annotations have RetentionPolicy set to RUNTIME which means that reflection is used in there.

Any reasonable implementation will probably minimize the use of reflection to initialization / deploy time, so looking up annotations probably won't be that big of a performance hit.

-Patrick

--
Patrick Linskey
http://bea.com

  Message #195421 Post reply Post reply Post reply Go to top Go to top Go to top

EJB3 entities are very different

Posted by: Patrick Linskey on December 29, 2005 in response to Message #195380
People have been criticizing EntityBean since it's inception. The main reason was you don't want to corrupt your domain/entity obejcts with some funny EJB interfaces. Besides this your domain object should not be constraint on any kind of container.

Bear in mind that EJB3 entities are very different than EJB2 and prior entity beans. EJB3 entities do not have any interface requirements, and certainly do not rely on the presence of a container.

-Patrick

--
Patrick Linskey
http://bea.com

  Message #195422 Post reply Post reply Post reply Go to top Go to top Go to top

Getting started with EJB 3.0 persistence out-of-container

Posted by: Shahzad Masud on December 29, 2005 in response to Message #195365
Many topics, I've seen this Persistence out-of-container. I don't know why? Persistence in EJB 3.0 is very nice and powerful. For this post, no comments!

  Message #195428 Post reply Post reply Post reply Go to top Go to top Go to top

Getting started with EJB 3.0 persistence out-of-container

Posted by: Steve Zara on December 29, 2005 in response to Message #195420
Any reasonable implementation will probably minimize the use of reflection to initialization / deploy time, so looking up annotations probably won't be that big of a performance hit.

And also, reflection has been highly optimised in recent versions of Java - it doesn't have the performance hit it used to.

  Message #195429 Post reply Post reply Post reply Go to top Go to top Go to top

Getting started with EJB 3.0 persistence out-of-container

Posted by: Marius Danciu on December 29, 2005 in response to Message #195420
Remember that EJB 3.0 annotations have RetentionPolicy set to RUNTIME which means that reflection is used in there.
Any reasonable implementation will probably minimize the use of reflection to initialization / deploy time, so looking up annotations probably won't be that big of a performance hit.-Patrick-- Patrick Linskeyhttp://bea.com

Refelction needs to be used to introspect annotations, however I would think that a reasonable implemetation would use it, only for initialization time to create the proxy (loadtime weaving - AOP style). Once proxy is there during runtine the beans should be managed quite effective and without any reflection. You could contradict me saying that reflection (on Java 5.0) improved quite well (or JRockit is quite efficient) but still can't be really compared with dirrect bytecode method invocation (invokevirtual etc.). So at the end of the day, reflection is just one concern.

  Message #195431 Post reply Post reply Post reply Go to top Go to top Go to top

Getting started with EJB 3.0 persistence out-of-container

Posted by: Alex Vasseur on December 29, 2005 in response to Message #195429
Marius

Your assumption is wrong.
Annotations (class retention and runtime retention) are structures that are in the bytecode. You can read them without ever loading the class or using java.lang.reflect, and this can thus be very fast without any kind of reflection related concern.
Of course, the reflect API also allow you to read the runtime ones - but that does not mean that all annotation based runtime / framework will use and possibly suffer from reflection in general.

Side note: interestingly out of the container Glassfish EJB3 (ie Oracle Toplink) requires a -javaagent option, which is a hint that bytecode manipulation is probably going on under the hood (and there is excellent ASM again as a dependency).
Kodo I think is quite similar with an enhancer, and Hibernate is using a cglib based proxy approach. So I am not sure someone is actually heavily using reflection there.
Left aside the impact delta between reflection and network roundtrip to database...

  Message #195435 Post reply Post reply Post reply Go to top Go to top Go to top

Getting started with EJB 3.0 persistence out-of-container

Posted by: Marius Danciu on December 29, 2005 in response to Message #195431
MariusYour assumption is wrong.Annotations (class retention and runtime retention) are structures that are in the bytecode. You can read them without ever loading the class or using java.lang.reflect, and this can thus be very fast without any kind of reflection related concern.Of course, the reflect API also allow you to read the runtime ones - but that does not mean that all annotation based runtime / framework will use and possibly suffer from reflection in general.Side note: interestingly out of the container Glassfish EJB3 (ie Oracle Toplink) requires a -javaagent option, which is a hint that bytecode manipulation is probably going on under the hood (and there is excellent ASM again as a dependency).Kodo I think is quite similar with an enhancer, and Hibernate is using a cglib based proxy approach. So I am not sure someone is actually heavily using reflection there.Left aside the impact delta between reflection and network roundtrip to database...

Alex, thanks for your reply. I am aware about Java 5 annotations and their retention policies ergo I should not have said "needs" in there (the right word probably would be "may" - sorry about the confusion). It is correct that this information exists at bytecode level, but it does not mean that vendors will not use reflection. I know that today's vendors for other appsrvs/frameworks (as you mentioned above) are using bytecode level manipulation using diferent tools, but the fact that EJB3 specs indicates that annotations have retention-poicy set to RUNTIME, nothing prevents a vendor to use reflection. All I'm saying is that before adopting a vendor for our applications, would be wise to ask the vendor how different concerns are addressed. As I said, reflection is just one concern. You correctly pointed that delta between reflection and network roundtrips can not really be compared but still we want fast application and we need to know the impact of EJB 3 O/R vendor implementation.
One other concern that one may have is when dealing with queries - remember N+1 query problem ? (there are solutions on the market today to solve this problem - one would be eager loading but that causes other problems that we may complain about - too much data :) ). So let's not forget that we are discussing entities outside of a Java EE container. This is why certain questions/concerns may rise.

  Message #195437 Post reply Post reply Post reply Go to top Go to top Go to top

Getting started with EJB 3.0 persistence out-of-container

Posted by: Emmanuel Bernard on December 29, 2005 in response to Message #195429
Refelction needs to be used to introspect annotations, however I would think that a reasonable implemetation would use it, only for initialization time [...]
What I've seen so far is that Annotations reading at init time even through java reflection is faster than XML reading. So there is no real concern here.

  Message #195441 Post reply Post reply Post reply Go to top Go to top Go to top

Getting started with EJB 3.0 persistence out-of-container

Posted by: Marius Danciu on December 29, 2005 in response to Message #195437
Refelction needs to be used to introspect annotations, however I would think that a reasonable implemetation would use it, only for initialization time [...]
What I've seen so far is that Annotations reading at init time even through java reflection is faster than XML reading. So there is no real concern here.

I think you are correct, but the point was reflection vs. dynamic proxies via bytecode manipulation.

  Message #195448 Post reply Post reply Post reply Go to top Go to top Go to top

Getting started with EJB 3.0 persistence out-of-container

Posted by: Davide Baroncelli on December 29, 2005 in response to Message #195437
Refelction needs to be used to introspect annotations, however I would think that a reasonable implemetation would use it, only for initialization time [...]
What I've seen so far is that Annotations reading at init time even through java reflection is faster than XML reading. So there is no real concern here.

Out of curiosity: how much? A little bit faster, considerably faster or ashamingly faster?

  Message #195451 Post reply Post reply Post reply Go to top Go to top Go to top

EJB3 entities are very different

Posted by: Rashid Jilani on December 29, 2005 in response to Message #195421
People have been criticizing EntityBean since it's inception. The main reason was you don't want to corrupt your domain/entity obejcts with some funny EJB interfaces. Besides this your domain object should not be constraint on any kind of container.
Bear in mind that EJB3 entities are very different than EJB2 and prior entity beans. EJB3 entities do not have any interface requirements, and certainly do not rely on the presence of a container.-Patrick-- Patrick Linskeyhttp://bea.com

Yes I know. The only thing is that it took almost 6 years what could have been easily done in very early days of EJB.

  Message #195465 Post reply Post reply Post reply Go to top Go to top Go to top

Afterwards

Posted by: Werner Punz on December 29, 2005 in response to Message #195451
People have been criticizing EntityBean since it's inception. The main reason was you don't want to corrupt your domain/entity obejcts with some funny EJB interfaces. Besides this your domain object should not be constraint on any kind of container.
Bear in mind that EJB3 entities are very different than EJB2 and prior entity beans. EJB3 entities do not have any interface requirements, and certainly do not rely on the presence of a container.-Patrick-- Patrick Linskeyhttp://bea.com
Yes I know. The only thing is that it took almost 6 years what could have been easily done in very early days of EJB.

It is very easy to say that afterwards, but fact is that it took many trials and then two really good OR mappers (Hibernate and Toplink) to find out what is working and which approaches are dead end.
If anyone ever had anything to do with the really lousy early Object db standards you know what I mean (ODMG1.0)

But afterwards everybody is always wiser than upfront.

  Message #195466 Post reply Post reply Post reply Go to top Go to top Go to top

EJB 3.0 persistence

Posted by: Randy Schnier on December 29, 2005 in response to Message #195365
It's good to see people documenting their experiences with the various containers; now we need to start seeing use cases and things that don't work with EJB3, so we can start building guidelines for when it should or shouldn't be used.

This is a good point.

I want to emphasize first that I'm very positive on the app development options the Java Persistence API brings to the table. (While often referred to as "EJB3 persistence", the official spec name is Java Persistence API -- it is a separate spec distinct from the EJB3 "core" spec, precisely because the JSR220 expert group envisioned a future where it could be used both inside and outside of JavaEE environments.)

As with most technical endeavors, definining how the Java Persistence API programming model was going to work involved some tradeoffs. These were all made consciously by the expert group for very good reasons and no doubt many developers will happily accept them (certainly those already using Hibernate, TopLink, JDO, etc.), but it is still good to know what those tradeoffs are. When using the Java Persistence API, your application must handle some things that the container previously handled for you.

- There is no (visible) interception performed on the Java Persistence API object methods. So, any security auth checking, transaction starting/completing, etc. needs to be performed by whoever is calling the method. Since it was best practice already to call entity beans from behind some kind of facade such as a servlet or session bean, this shouldn't be a big change.

- Java Persistence API object instances are local-only. You can pass them by-value to another process, but they then lose their association with the EntityManager in your process. Any updates you make to that object after that point won't be made persistent unless you re-associate the object with its EntityManager. (You can re-associate the object with the EntityManager at a later time by using the merge() API.)

- Your application controls the instance lifecycle of Java Persistence API objects, and interacts directly with the "real" instance of your object.

- If you have a bi-directional relationship defined between two persistent objects and remove one of the objects, your application is responsible for updating the pointer in the "other" object.

Like I said, anyone already using Hibernate, TopLink, or a similar product is already familiar with these, but developers currently using pre-3.0 entity beans will need to be aware of them.

  Message #195474 Post reply Post reply Post reply Go to top Go to top Go to top

Afterwards

Posted by: Steve Zara on December 29, 2005 in response to Message #195465
It is very easy to say that afterwards, but fact is that it took many trials and then two really good OR mappers (Hibernate and Toplink) to find out what is working and which approaches are dead end.

Not to mention the various JDO vendors and experts who were on the JSR 220 expert group, and presumably contributed to the specification.

  Message #195480 Post reply Post reply Post reply Go to top Go to top Go to top

Afterwards

Posted by: Rashid Jilani on December 29, 2005 in response to Message #195465
People have been criticizing EntityBean since it's inception. The main reason was you don't want to corrupt your domain/entity obejcts with some funny EJB interfaces. Besides this your domain object should not be constraint on any kind of container.
Bear in mind that EJB3 entities are very different than EJB2 and prior entity beans. EJB3 entities do not have any interface requirements, and certainly do not rely on the presence of a container.-Patrick-- Patrick Linskeyhttp://bea.com
Yes I know. The only thing is that it took almost 6 years what could have been easily done in very early days of EJB.
It is very easy to say that afterwards, but fact is that it took many trials and then two really good OR mappers (Hibernate and Toplink) to find out what is working and which approaches are dead end.If anyone ever had anything to do with the really lousy early Object db standards you know what I mean (ODMG1.0) But afterwards everybody is always wiser than upfront.

My friend I am not here to win "who is wiser" contest. At least that is not my intention, specially in a community where people still can have a war on the text editors:-)

I don't know how long you have been particpating on TSS forum, but believe me many Java developers have been up front and criticizing entity beans way before you can imagine as well as way before many famous EJB vendors implemented the container managed persistence:-) Besides that Some of these developers also implemented the container managed persistence for some early EJB containers not to mention that most of them vainshed in the dot com bubble blast era. Besides that you don't need a trial and error to figure out every thing, some time it is just common sense.

BTW I just want to let you know I am not criticizing any one here. If it is any thing, it's an appreciation that finally we all learned how to do things in the right way.

  Message #195481 Post reply Post reply Post reply Go to top Go to top Go to top

Afterwards

Posted by: Werner Punz on December 29, 2005 in response to Message #195480
My friend I am not here to win "who is wiser" contest. At least that is not my intention, specially in a community where people still can have a war on the text editors:-) I don't know how long you have been particpating on TSS forum, but believe me many Java developers have been up front and criticizing entity beans way before you can imagine as well as way before many famous EJB vendors implemented the container managed persistence:-) Besides that Some of these developers also implemented the container managed persistence for some early EJB containers not to mention that most of them vainshed in the dot com bubble blast era. Besides that you don't need a trial and error to figure out every thing, some time it is just common sense. BTW I just want to let you know I am not criticizing any one here. If it is any thing, it's an appreciation that finally we all learned how to do things in the right way.
Well the problem as I see it is less, that the implementation was broken and people saw it, that happens often (ODMG 1 I mentioned early is the perfect example of such an unusable spec) but to get it right.
Face it, at the time the entity beans were implemented first
to my knowledge there was no real well working object persistence layer experience on the java side.
ODMG 1 was a desaster, hugely to blame on the half baked OQL and a standard with holes bigger than a fishnet to ensure vendor apis have to be used.
Some of the stuff still was under research (lifecycle conditions how does the object lifecycle handling works best on an OO DB/ORM environment etc...)

So you have a broken implementation of a somewhat not fully
researched area, people said its broken, the standard was altered, people still said its broken. In the meanwhile several ORM implementations have arrived which got things finally right. The standard is altered a third time to adjust to this experience and got things finally dead right, and then people complain it should have been done right the first time.

Sorry, but that is somewhat harsh given the full situation.
And yes you are right some things are common sense, but many things not (having to define a query language on an OODB system which works really well is not a trivial task, hence the early oql implementations got the basic ideas right bug crumbled upon day to day needs, which also have to have set operations and reverse referencing in mind)
The query languages are the perfect example of saying this is common sense, but yet it took many years and trial and errors to got something scalable up and running in those systems, and yet there are still fallback options into lower parts of the query system just in case you need them (which you sometimes do)

  Message #195482 Post reply Post reply Post reply Go to top Go to top Go to top

Afterwards

Posted by: Rashid Jilani on December 29, 2005 in response to Message #195481
Face it, at the time the entity beans were implemented firstto my knowledge there was no real well working object persistence layer experience on the java side.

your favourite TOPLink was there for Java, way before any one heard the EE's in Java. The Toplink people have brought years of experience(with all the trail and errors) from some other OO languages and gave us a pretty reasonable O/R mapping tool even then. It seems to me good or bad after so many years of trial and errors we are back to square one. We could have shorten the path, if we would have been open enough to learn from other people experience too.

  Message #195488 Post reply Post reply Post reply Go to top Go to top Go to top

Getting started with EJB 3.0 persistence out-of-container

Posted by: Jan de Jonge on December 29, 2005 in response to Message #195368
Gavin, I don't think you understood the article initially. Just saw "out-of-container" and rushed to conclusion without reading the whole article. May you need some more sleep, man! :)

  Message #195495 Post reply Post reply Post reply Go to top Go to top Go to top

Annotations

Posted by: Rob Rudin on December 29, 2005 in response to Message #195365
Perhaps I'm in the minority, but I don't see what the benefits of using annotations are here. Consider 2 domain classes that really would be reusable - a Path class that has a list of Location classes, where each Location has a latitude, longitude, and an elevation. And the Location class would have nice methods like "getDistanceTo(Location)" and other things that do nice math stuff for you. Domain objects that could really be reused on other systems. And I'd like to be able to save instances of Path to a database. But in making this code reusable, the last thing I'd want to do is specify table/column mappings that other developers would have to use (and I don't want to hand over the source code, in order to prevent it from being forked on a bunch of other projects). I assume there's some ability to override annotations, but wouldn't that be done externally, like in an XML file? In which case I'd find that more confusing - some mappings would be done in annotations, some would be overridden externally.

Are persistence annotations really an improvement over having all of the mappings externalized in XML files? I've been using Hibernate for a few years, and even on a project with over 100 classes mapped using Hibernate, the amount of XML was really quite easy to manage.

Maybe there's just some annotation Kool-Aid to drink and I've yet to do so. Part of me wonders if annotations are a reaction to how .NET developers could make a method a web service through some annotation-like syntax. That never seemed useful to me - sure, it's nice and easy, but on a large system, is that really the best way to manage what gets exposed as a web service? Same question for annotations - sure, a lot of cool things can be done with them, but are they really the best choice in the long run? Would like to know why others are excited about using annotations, and hopefully the answers are more than "XML is ugly", as there are some significant benefits to having metadata externalized in XML as opposed to inlined via annotations.

Rob

  Message #195504 Post reply Post reply Post reply Go to top Go to top Go to top

Annotations

Posted by: Sahoo Sanjeeb on December 30, 2005 in response to Message #195495
You will find divided opinion about using annotations to specify table and column names. Using annotations to specify table or column names is not very different from using embedded SQL in an application which was a common practice not so long back and many of those systems are still very much active in this internet world. Like every feature, this feature also have some valid use cases and it is not so useful in some cases (e.g. the one you pointed out).

I don't think there is anything wrong in having such a facility in Java EE platform. More over, I don't think Java EE 5 platform says any where that XML is ugly. Let users choose what they want to specify using annotations and what using XML DD. I see large applications using a mixed approach. In real world applications the way I see it being used is that the information that is taken at development time should be provided using annotations. Deployment time configuration information will be done using XML.

Finally as you pointed out, annotations certainly help in developing applications easily and quickly. This is where J2EE was loosing to .NET. One of the goals of Java EE 5 is to make the platform easy to learn/use. The reason you are seeing so many articles talking about annotations is probably because it is a relatively new language feature and people are trying to educate people about how to use it.

-- Sahoo

  Message #195508 Post reply Post reply Post reply Go to top Go to top Go to top

Another advantage of annotations

Posted by: Werner Punz on December 30, 2005 in response to Message #195504
Well the poster before me pointed out that annotations help to develop apps more quickly.
The two most famous examples probably are
@Webmethod
and
@Transactional

in one case you do not get the whole wsdl-xml mess which is really lousy to handle, no stubs and no skeletons

in the other case all the transactional code is moved into one declaration above the method.
What happens here, is that the glue code, which was most of the times hidden in the pre web application area and suddenly moved into the app coding layer in the web application area, is moved back into the place where it belongs, the engines, and the libraries and the people finally can concentrate back on the application logic instead of having to juggle around glue code 80% of the times.

The other huge advantage of all this is, that generally if well designed (and the ejb3 annotations are really well designed) annotations are way less verbose than xml. They have a tighter syntax, are there where you need them most, right at the code and for most things introspection does the trick. A typical ejb3 entity bean usually has 2-3 annotations per class, compared to 10-15 glue field declarations in xml in the same xml file + a tld heading + the usual xml verbosity + you have to juggle two files at the same time constantly.

The only disadvantage you get is that you lose the central config point xml gives you, which can be a huge issue.

  Message #195513 Post reply Post reply Post reply Go to top Go to top Go to top

Another advantage of annotations

Posted by: Henrique Steckelberg on December 30, 2005 in response to Message #195508
Don't forget also all the people who were happy XDoclet users, which have used annotations way before .Net came up, and may gladly migrate to standard annotations now in EJB3. Whomever prefers XML will be able to keep using it too, so I think this is a win-win solution.

  Message #195514 Post reply Post reply Post reply Go to top Go to top Go to top

Annotations

Posted by: Artur Karazniewicz on December 30, 2005 in response to Message #195495
Perhaps I'm in the minority, but I don't see what the benefits of using annotations are here. Consider 2 domain classes that really would be reusable - a Path class that has a list of Location classes, where each Location has a latitude, longitude, and an elevation. And the Location class would have nice methods like "getDistanceTo(Location)" and other things that do nice math stuff for you. Domain objects that could really be reused on other systems. And I'd like to be able to save instances of Path to a database.

I'm not keen on annotations here too. It is not actually transparent POJO persistence like Hibernate used to be for years. You have to import all that annotations into Your source code (On the other hand it's incredibly convenient, and IMO far better when it comes to maintenance).

Latest spec. provides alternative way using xml. But i'm still missing things like Hibernate's 'named entities'. There is no way to map one class few times in different contexts, thus really reuse basic entities within application. Typical problem is for example Address class. There is no need to have OfficiallAddress, and LivingAddress classes but only one class - Address reused in different contexts...

Artur

  Message #195515 Post reply Post reply Post reply Go to top Go to top Go to top

adjust your though patterns

Posted by: Werner Punz on December 30, 2005 in response to Message #195514
There is no way to map one class few times in different contexts, thus really reuse basic entities within application. Typical problem is for example Address class. There is no need to have OfficiallAddress, and LivingAddress classes but only one class - Address reused in different contexts...Artur

You have to get out of the xml thinking in this case, interfaces do the trick here...
two different interfaces on the same class basically give
the same result than having two different entity definitions
upon the same class with different attributes...

  Message #195520 Post reply Post reply Post reply Go to top Go to top Go to top

adjust your though patterns

Posted by: Artur Karazniewicz on December 30, 2005 in response to Message #195515
There is no way to map one class few times in different contexts, thus really reuse basic entities within application. Typical problem is for example Address class. There is no need to have OfficiallAddress, and LivingAddress classes but only one class - Address reused in different contexts...Artur
You have to get out of the xml thinking in this case, interfaces do the trick here...two different interfaces on the same class basically givethe same result than having two different entity definitionsupon the same class with different attributes...

But it doesn't resolve the problem. Consider this (assume, for sake of brevity it's unidirectional):

<code>
@Entity
public class Person {
  @OneToOne
  Address livingAddress;
}

@Entity
public class Enterpise {
  @OneToOne
  Address address;
}
</code>

Now assume that both addresses are stored in different tables or are 'components' (like in hibernate's "component" mapping) of their entities.

Additionally it's completly non intuitive. Why do I need to have an interface plus two clasess just to implement the same thing - Address. How Enterprise's Address is different from Person's Address or how living address is different from official/other address when thinking about domain model? I just don't want implement two classes + interface that abstracts exactly the same thing because of limitations of persistence layer. Just my opinion.

I think notion of named entities is one of the biggest improvements of hibernate since 2.0. And Gavin doesn't adds unecessary features - believe me :))).

Artur

  Message #195524 Post reply Post reply Post reply Go to top Go to top Go to top

adjust your though patterns

Posted by: Emmanuel Bernard on December 30, 2005 in response to Message #195520
How Enterprise's Address is different from Person's Address or how living address is different from official/other address when thinking about domain model? I just don't want implement two classes + interface that abstracts exactly the same thing because of limitations of persistence layer.
Why is it represented in different tables in your relational model. There must be a reason for that.

  Message #195529 Post reply Post reply Post reply Go to top Go to top Go to top

adjust your though patterns

Posted by: Artur Karazniewicz on December 30, 2005 in response to Message #195524
Why is it represented in different tables in your relational model. There must be a reason for that.

There might be plenty of reasons:

1. security (only authorized users can view/change personal data, but everyone can view Enterprise address) - speaking about security I mean phisical database security (roles/grants) ruled by law in many countries.

2. Sometimes it's convenient to store this type of data as a component (true one-to-one relation).

3. sake of normalisation, it's is not an elegant way to mix all addresses into one table (IMO) sometimes. For example what if i had select only enterprise addresses within NYC but not those connected to people, or what if had to send christmass postcards to people living in Poland, but of course it makes no sense to send it to both addresses (Living, Official)? And many, many use cases. (Of course I can use some kind of "type", but it's not elegant IMO).
 
4. lagacy database...

etc. etc.

Artur

  Message #195561 Post reply Post reply Post reply Go to top Go to top Go to top

Getting started with EJB 3.0 persistence out-of-container

Posted by: Sreenath V on December 30, 2005 in response to Message #195365
With EJB 3.0 writing an Entity bean and Session bean is just more than a cake walk... Really i love the EJB 3 specifications...

  Message #195658 Post reply Post reply Post reply Go to top Go to top Go to top

Annotations

Posted by: Gavin King on December 30, 2005 in response to Message #195514
I'm not keen on annotations here too. It is not actually transparent POJO persistence like Hibernate used to be for years. You have to import all that annotations into Your source code (On the other hand it's incredibly convenient, and IMO far better when it comes to maintenance).

Well, "convenient" and "maintainable" are real requirements - "transparent" is not. It's not like XML-based Hibernate applications had no dependency to Hibernate ;-)

Latest spec. provides alternative way using xml. But i'm still missing things like Hibernate's 'named entities'. There is no way to map one class few times in different contexts, thus really reuse basic entities within application.

Funnily enough, my original proposal for the EntityManager API actually did have support for named entities in it. And this was actually in the spec for quite a while (it might have even made it into the first spec draft, I forget now).

But what happened was that Oracle and Solarmetric wanted it taken out, and I figured "well, Hibernate did not even have this feature until 3.0, so clearly it was not such a critically huge issue for most people". So we took it out.

And I don't recall anyone emailing the EJB feedback alias asking for this feature - so you have only yourselves to blame if you need this j/k ;-)

A workaround is to use multiple EntityManagerFactory instances. But of course you can't then have associations...

  Message #195678 Post reply Post reply Post reply Go to top Go to top Go to top

Annotations

Posted by: Juozas Baliuka on December 31, 2005 in response to Message #195658
Workaround is to duplicate class definitions and to use common interface. It is not a problem if code is generated :)

New content on TheServerSide.comNew content on TheServerSide.comNew content on TheServerSide.com

Dependency Injection in Java EE 6 - Part 2

Reza Rahman continues to explore the features of the proposed JSR 299, Contexts and Dependency Injection for Java EE (CDI). When approved, it promises to be a key feature of Java EE 6. (January 21, Article)

Ted Neward Q&A: What you must know about JavaScript, Scala and more

Ted Neward is an independent consultant specializing in high-scale enterprise systems, and an authority in Java and .NET technologies. He is the author and co-author of several books, including Effective Enterprise Java. At TheServerSide Java Symposium in March, he will be presenting sessions on pragmatic architecture, ECMAScript and Scala. (January 15, Article)

Developers split on open sourcing Java

Now that Oracle is absorbing Sun Microsystems, there mixed views on what should come of the Java Community Process (JCP). While some say Oracle should become the new steward of Java and keep the JCP much as it was, others argue that it may be time to open-source this widespread language. (November 24, Article)

Dependency Injection in Java EE 6 - Part 1

Reza Rahman explores the features of the proposed JSR 299, Contexts and Dependency Injection for Java EE (CDI). When approved, it promises to be a key feature of Java EE 6. (November 2, Article)

SAML: It's Not just for Web services

SAML is an XML-based standard for exchanging authentication and authorization data between security domains. The single most important problem that SAML was created to solve is the Web browser Single Sign-On problem. Many organizations are debating whether to stay with version 1.1 or move to 2.0. This article makes observations about both options. (September 28, Article)

Programming is Also Teaching Your Team

Joe Ottinger takes a look at how people learn, and applies it to the practice of programming. He notes that understanding how people learn is an essential part of working in a programming team. (September 22, Article)

Can Java EE Deliver The Asynchronous Web?

Stephen Maryka gave us an article about the Asynchronous Web and posed a number of questions that get examined like an approach to delivering Asynchronous Web capabilities through extensions to existing Java EE technologies. (July 14, Article)

JSF Flex

JavaServer Faces Flex goal is to provide users capability in creating standard Flex components, part of flexSDK which is open sourced through MPL license, as normal JSF components. This article by Ji Hoon Kim will provide an overview of creating a simple multilingual JSF page consisting of JSF Flex tags. (June 29, Article)

The Rules of SOA - A Road to a Successful SOA Implementation

In this session Jeff explores the key characteristics of successful SOA projects. He covers some of the patterns, and anti-patterns, tool sets, and strategies that he himself learned the hard way. Last, he provides a strategy and blueprint for achieving a high likelihood of success in your SOA project. (June 23, Tech Talk)

Ari Zilka Talks About Terracotta 3.1

Ari Zilka, CTO of Terracotta, Inc., talks about the new features in Terracotta 3.1, announced during JavaOne and available now. (June 15, Tech Talk)

Enterprise Application Integration, and Spring

In this Tech Talk, Josh Long explores an integration challenge using Spring Integration and walks through the implementation, employing and expanding on the basic patterns of Enterprise Application Integration to tie together components into a function integration solution, and then demonstrates how Spring Integration helps address the integration requirements. (June 15, Tech Talk)

Google Web Toolkit: An Introduction

In this Tech Talk, David Geary teaches you: The basics of Google Web Toolkit; How to implement Ajax-enabled applications in Java; Internationalization; Hooking into the browser history mechanism; Remote procedure calls. (June 4, Tech Talk)

Just Enough Early Architecture to Guide Development

Jon Kern discusses the best architecture/technical solutions and ensure that they are repeated by all developers. By tackling the architecture up-front in a serial manner, subsequent parallel development will be much more manageable and predictable. (May 28, Tech Talk)

Productive Programmer: On the Lam from the Furniture Police

This keynote describes the frustrations of modern knowledge workers in their quest to actually get some work done, and solutions for how to guard yourself against all those distractions. Neal Ford talks about environments, coding, acceleration, automation, and avoiding repetition as ways to defeat the misguided attempts to sap your ability to produce good work. (May 26, Tech Talk)

Auto-Scaling Your Existing Web Application

Gil demonstrates how new, aggressive uses of already abundant compute capacity by common applications offer competitive value for application designers. (May 21, Tech Talk)

Automating Hibernate Mapping and Queries For Java Web Development

Chris Keene introduces WaveMaker as a new way to automate the ability to generate Hibernate classes in order to more quickly bring OR mapping into an application. (May 19, Article)

Free Book PDF Download: Mastering EJB Third Edition

Mastering EJB was one of the original and most influential EJB books in the industry. Mastering EJB III now returns with two new expert co-authors, updated for EJB 2.1 and 30% new chapters including security, integration, best practices, open source, and more.
(Book PDF Download)

Application Server Matrix

The Application Server Matrix is a detailed listing of J2EE vendors and their application server products, with information on latest version numbers, J2EE spec support and licensing, pricing, platform support, and links to product downloads and reviews.
(Application Server Comparison Matrix)

News | Blogs | Discussions | Tech talks | Patterns | Reviews | White Papers | Downloads | Articles | Media kit | About
Java Solutions
All Content Copyright ©2007 TheServerSide Privacy Policy
Site Map