Using composition over inheritance is a common design pattern that is often discussed in terms of designing business logic components. However, composition can solve a number of problems in domain object modeling that are created by relying on inheritance to share interface or functionality. Composition is used to delegate implementation in logical units by enlisting the help of a reference to an object that implements the required functionality instead of inheriting from it. This reference can be changed to different implementations depending on the needs at the time making for a more flexible design. This same design can be used in domain modeling to overcome some of the problems caused by inheritance. The typical flawed example of using inheritance in object modeling is the Person class which is often subclassed into Employee, User , Customer and Vendor classes.
Read the rest of this entry »
Posts Tagged jpa
Java EE 6 Is Here
Dec 10
Like Christmas come early, Sun announced the release of JEE 6. This release sees continued improvement in the JEE stack with the inclusion of JSR 299, Java Contexts and Dependency Injection (CDI), and EJB 3.1 as well as JSF 2.0, and JPA 2.0. JSF especially has seen changes as a result of practical user feedback and community add-ons such as Seam and JSF Ajax frameworks which have contributed back to the JCP.
Glassfish v3 which implements the full JEE 6 stack has also been released, with JBoss’ Weld as the CDI implementation. Netbeans 6.8 has also been released with full JEE 6 project support including maven support for enterprise applications. Also of note is the hot deploy function of Glassfish which can deploy your app while maintaining session information.
Personally, I’m pleased. JEE 6 has really improved things for the java standards, and CDI has filled some gaps that previously required different additional pieces to completely fill. The ghosts of EJB 2.1 should now be permanently laid to rest, but should serve as a stark reminder. Having good frameworks to build standards based solutions is always good for the community.
I’ll try and get some tutorials on developing with CDI and JSF 2.0 with Netbeans and Glassfish out soon.
I’ve spent some time in the last couple of weeks playing around with Glassfish, Netbeans 6.8 Beta (and milestone 2 before it) and JSF 2.0, and I have to say that this is turning out to be a really good set of development libraries and tools.
Read the rest of this entry »
Here’s a couple of links regarding building Multi Module Apps with the Hibernate JPA Implementation. It was a subject I was starting to look at and these two articles just happened to cover both areas that I was interested in. Thought I’d share them and if nothing else, I know where to find them the next time I need them.
One of the problems faced by Seam users is the disconnect between the session scoped entity instances and using them in more local scopes. A good example is a session scoped User instance that is loaded when the user logs in and is outjected into the session scope. This user instance is available for the duration of the users session.
This user entity is great for displaying who the logged in user is and other information. The problem comes when you
need to use that User entity in conjunction with other entities that are managed by the locally scoped entity manager. If an entity has a property that references the current user (such as a createdBy property), then it might seem obvious to assign the User variable value to that value. However, the User is unmanaged by the entity manager for that conversation and will raise errors when you try and save the entity referencing the unmanaged User.
We could make the instance managed before we save it or assign it to the property, but this is a session scoped instance, and it could be shared among multiple conversations. We may want to compare the instances at different times in the same conversation which will break if it has been altered by another conversation. Also, we don’t want to
have to write code to handle each property assignment or saving each entity type. Read the rest of this entry »
