<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Andy Gibson &#187; JPA</title>
	<atom:link href="http://www.andygibson.net/blog/tag/jpa/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.andygibson.net/blog</link>
	<description>Open Source Projects &#38; Technical Writings</description>
	<lastBuildDate>Fri, 30 Jul 2010 02:42:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>FlutterCode.com released</title>
		<link>http://www.andygibson.net/blog/news/fluttercode-com-released/</link>
		<comments>http://www.andygibson.net/blog/news/fluttercode-com-released/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 02:48:18 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[CDI]]></category>
		<category><![CDATA[Geek]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[Podcast]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=919</guid>
		<description><![CDATA[I&#8217;ve been fairly quiet over the last couple of months as I&#8217;ve been working on a few items, working on a new site and working on getting two new Open Source projects final and out the door. 
I&#8217;ve renamed Spigot to DataValve, and moved it to the new site FlutterCode.com which will also host my [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been fairly quiet over the last couple of months as I&#8217;ve been working on a few items, working on a <a href="http://www.fluttercode.com">new site</a> and working on getting two new Open Source projects final and out the door. </p>
<p>I&#8217;ve renamed Spigot to <a href="http://www.fluttercode.com/projects/datavalve">DataValve</a>, and moved it to the new site FlutterCode.com which will also host my other project called <a href="http://www.fluttercode.com/projects/knappsack">Knappsack</a> which is a set of Maven archetypes for Java EE 6.</p>
<p>The new site will be home to most of my tutorials, articles and other writings, as well as possibly some screencasts and even podcasts. It will in essence be a pure java development site. This blog will go a bit quieter and contain less development stuff, although most opinion will get put out here instead of over there. I&#8217;ll also be copying some of my tutorials over there from this blog.</p>
<p>I&#8217;m aiming to create a fairly cohesive tutorial site, aided in part by the Maven Archetypes which will give me a firm base onto which I can build tutorials without having to start from scratch, but one archetype is a sandbox Java EE 6 app with project configuration, a demo model and some test data. The sandbox app will let developers create a new skeleton java EE 6 application they can play with. Building on that, there is a sandbox-demo application which as an archetype that creates a full working demo CRUD application using Java EE 6 so developers can see how all the different pieces of Java EE 6 go together. It includes features such as conversations, JPA CRUD, page parameters, CDI injection and events.</p>
<p>Again, I have to say it, but  <a href="http://www.andygibson.net/blog/index.php/2009/07/12/open-source-is-hard/">Open Source is Hard</a>. In the past couple of months, I have been working on a whole new site, getting 2 projects ready to roll with documentation and site content to boot as well as working a job, and having some kind of life.</p>
<p>Now it&#8217;s out, I can start to focus a little more on getting some more Java EE 6 tutorials and articles out.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/news/fluttercode-com-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Guide to Spigot For Seam Developers</title>
		<link>http://www.andygibson.net/blog/article/spigot-for-seam-developers/</link>
		<comments>http://www.andygibson.net/blog/article/spigot-for-seam-developers/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 17:00:57 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[CDI]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Project Kenai]]></category>
		<category><![CDATA[Seam]]></category>
		<category><![CDATA[Spigot]]></category>
		<category><![CDATA[Weld]]></category>
		<category><![CDATA[Wicket]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=874</guid>
		<description><![CDATA[Note : Spigot has been renamed to DataValve.
(Edit : I renamed this post so it doesn&#8217;t seem like Spigot is just for Seam, Spigot can be used with different frameworks or without any at all. However, I wrote this post since Spigot is so familiar to the Seam EntityQuery that it should be easy for [...]]]></description>
			<content:encoded><![CDATA[<p><b>Note</b> : Spigot has been renamed to <a href="http://www.fluttercode.com/projects/datavalve/">DataValve</a>.</p>
<p>(<small><b>Edit </b>: I renamed this post so it doesn&#8217;t seem like Spigot is just for Seam, Spigot can be used with different frameworks or without any at all. However, I wrote this post since Spigot is so familiar to the Seam EntityQuery that it should be easy for Seam users to get the idea</small>)</p>
<p>Seam developers should become familiar with <a href="http://kenai.com/projects/spigot/">Spigot</a> concepts fairly quickly since they are very similar to those found in the Seam <code>EntityQuery</code> which was one of the main inspirations for the framework. If you imagine taking the entity query class and splitting it in two, one part to keep hold of state and the other to actually fetch the data. The stateful part is the <code>Paginator</code> that keeps track of what the current ordering of the data is, what is the current page and how big the pages are. The stateless part takes the Ejbql and the pagination information and returns a subset of the data. Now imaging that the data provider has the JPA pieces taken out and replaced with an abstract <code>fetchResults</code> method. This method is implemented in subclasses for specific data providers for text files, sql queries, jpa queries, native jpa queries, xml files, comma delimited or just an in memory dataset.<br />
<span id="more-874"></span><br />
I also abstracted the concepts of parameterization and parameter resolution so you can have parameters on data providers that are no t query based and your parameters can be resolved using different mechanisms such as EL, reflection, a map, or using custom parameter resolution.<br />
So really, for Seam developers, its like a Seam <code>EntityQuery</code> that doesn&#8217;t just use JPA, but uses any kind of data source you want but still returns just a list of objects.</p>
<p>Spigot works nicely with CDI and there is even a demo of it in the distribution that uses JSF and was generated using the Weld maven archetypes. Also, there is a Seam Jpa Dataset Adapter that you can use as a direct replacement for the <code>EntityQuery</code> which will adapt the entity query calls to the underlying data provider calls so you can have a seam-less transition if you want to switch over. This is still a little in-progress, but works. The one area that isn&#8217;t implemented is the sorting, which may not be possible, but I still need to add in the methods to the adapter even if they don&#8217;t do anything. The other issue is of course the configuration of the query from components.xml using the Seam Framework tags. However, you can define the query using regular component xml tags to define the Ejbql, restrictions and page sizes.</p>
<p>Two things to note if you start using Spigot in place of the entity query. All rows are returned by default, and you need to specify both a select statement and a count statement. I separated those two out so you can put join fetch phrases in the select statement without it breaking the count statement. There is an <code>init</code> method that you can use to set both of these statements for a class type.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/article/spigot-for-seam-developers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Spigot 0.9.CR1 released</title>
		<link>http://www.andygibson.net/blog/news/spigot-0-9-cr1-released/</link>
		<comments>http://www.andygibson.net/blog/news/spigot-0-9-cr1-released/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 13:07:55 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[CDI]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[Seam]]></category>
		<category><![CDATA[Spigot]]></category>
		<category><![CDATA[Weld]]></category>
		<category><![CDATA[Wicket]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=861</guid>
		<description><![CDATA[Note : Spigot has been renamed to DataValve and is hosted over on FlutterCode.com.
It&#8217;s been a while since I&#8217;ve posted anything new as I&#8217;ve been busy with a new Open Source software project called Spigot. It&#8217;s a java library that sits between your application code and your data sources (Hibernate, JPA, JDBC or any arbitrary [...]]]></description>
			<content:encoded><![CDATA[<p><b>Note</b> : Spigot has been renamed to <a href="http://www.fluttercode.com/projects/datavalve/">DataValve</a> and is hosted over on <a href="http://www.fluttercode.com">FlutterCode.com</a>.</p>
<p>It&#8217;s been a while since I&#8217;ve posted anything new as I&#8217;ve been busy with a new Open Source software project called Spigot. It&#8217;s a java library that sits between your application code and your data sources (Hibernate, JPA, JDBC or any arbitrary source of data) and helps with things like pagination and sorting using a common interface so you can switch out data providers and use alternatives. </p>
<p>For query language data providers, Spigot also facilitates excluding restrictions from WHERE clauses when parameters are resolved to null. Parameters are handled using parameter resolvers so there is more than one way to parameterize the query including EL expressions, reflection or a value map on the data provider.</p>
<p>Spigot also provides a few other add-ins like converting any dataset into an in-memory dataset that can itself be paginated and sorted and shared across an application (such as commonly used data in a web application). The <code>IndexedDataProviderCache</code> can give you random access into a dataset with caching and look ahead loading. This lets you hook a dataset with thousands of rows up to a Swing JTable with an instant response and a very small memory footprint since it doesn&#8217;t need to load all the objects at once as the provider will load the records as needed and cache the results. This is demonstrated in the Swing Demo in the download. There are also demos for Wicket and CDI with JSF.</p>
<p>You can ready about why I created Spigot in the <a href="http://spigot.kenai.com/docs/html/pr01.html">documentation</a></p>
<p>Spigot is currently hosted on <a href="http://www.projectkenai.com/projects/spigot/">Project Kenai</a>, where you can download the release, view documentation online or read about <a href="http://kenai.com/projects/spigot/pages/10WaysSpigotHelpsDevelopers">10 ways Spigot helps developers</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/news/spigot-0-9-cr1-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Composition in Object Modeling</title>
		<link>http://www.andygibson.net/blog/article/using-composition-in-object-modeling/</link>
		<comments>http://www.andygibson.net/blog/article/using-composition-in-object-modeling/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 14:33:35 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Journeyman]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[Modeling]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=765</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>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 <code>Person</code> class which is often subclassed into <code>Employee</code>, <code>User</code> , <code>Customer</code> and <code>Vendor</code> classes.<br />
<span id="more-765"></span></p>
<pre class="brush: java;">
public class Person {

  private Long id;
  private String firstName;
  private String lastName;
}
</pre>
<pre class="brush: java;">
public class User extends Person {

  private String userName;
  private String password;

}
</pre>
<pre class="brush: java;">
public class Customer extends Person {

  private int creditLimit;

}
</pre>
<pre class="brush: java;">
public class Employee extends Person {

  private Date beginDate;
  private Date endDate;

}
</pre>
<p>The classic problems here are that a customer may not always be a person, and a person may be both a customer and a vendor and possibly even be an employee and user. It also ignites the age old debate of whether a user must be an employee or all employees are also users. Using inheritance severely restricts us by taking away our one chance to inherit from a single class and limits our future plans since we are claiming some hard rules such as &#8220;every user is a person&#8221;. </p>
<p>Also, how do we handle a person that leaves the company and comes back? Do we have two different instances of this person in the system? For that matter, most Person instances will be duplicated if a person is a customer and a user and employee. This also leads to problems with things like name changes where one version gets updated but the other doesn&#8217;t.</p>
<h1>Role your own</h1>
<p>One common solution to this problem is to let the <code>Person</code> entity have a collection of roles that they perform so they can be either a user,an employee, a customer or vendor at the same time. This does solve the problems of not having to worry about inheritance hierarchies and whether a user is an employee or vice versa and also lets a person play all those roles at once. However, it only works where you know that every user, customer, vendor or employee will be a person.<br />
It&#8217;s also not very clear how we should reference these entities. If I have an order and need to reference a customer, do I reference the person or the persons customer role? </p>
<h1>Compose Yourself</h1>
<p>Alternatively you can use composition to model the relationship instead of inheritance. We can define a <code>Person</code> class which models just a person and we model Customers and Employees as separate classes that encapsulate the information specific to that role and has a reference to the person associated with it.The benefit here is that the different classes do not have to be subclassed from the <code>Person</code> class which lets us inherit from whatever we want.</p>
<pre class="brush: java;">
public class User {

  private Long id;
  private String userName;
  private String password;
  private Person person;
}
</pre>
<p>and</p>
<pre class="brush: java;">
public class Customer {

  private Long id;
  private Person person;
  private int creditLimit;
}
</pre>
<pre class="brush: java;">
public class Employee {

  private Long id;
  private Person person;
  private Date beginDate;
  private Date endDate;
}
</pre>
<p>We don&#8217;t have to worry about whether <code>Employee</code> should inherit from a <code>User</code> or vice versa since they are entirely different entities but they reference the same person instance. We still have the ability to check for things like users that are employees by finding users and employees that have a matching person reference. Modeling for each of the entities is kept specific to what the entity represents. A customer contains customer information and an employee contains employee information with only a single reference to the person it is representing. </p>
<p>This solves our original problems, but also gives us far more in return. It is a far more flexible design because we can expand the definitions of the classes beyond the hard restriction that every customer must be a person. Let&#8217;s consider a situation where the developers have been asked to allow businesses to also be defined as customers in the system. With the Customer subclassing from Person design it would be a nightmare to change the code to accommodate this. On the other hand, if we designed Customer to use composition, we can easily resolve the problem.</p>
<pre class="brush: java;">
public abstract class AbstractCustomer {

  private Long id;
  private int creditLimit;
  public abstract String getName();
}
</pre>
<p>We can create a person based customer by subclassing it and adding a reference to the person.</p>
<pre class="brush: java;">
public class PersonCustomer extends AbstractCustomer {

  private Person person;

  public abstract String getName() {
    return person.getName();
  }
}
</pre>
<p>For a company based customer, we can again subclass it, this time adding a <code>Company</code> reference. </p>
<pre class="brush: java;">
public class CompanyCustomer extends AbstractCustomer {

  private Company company;

  public abstract String getName() {
    return company.getName();
  }
}
</pre>
<p>Notice that in the abstract base class, we define the <code>getName()</code> method to return the name of the customer. This is made abstract and must be implemented in subclasses specific to the type of customer we are implementing. As a general rule, like any inheritance, common attributes that apply to all types of the entity should go in the base class because then you will be able to call those methods on references to the entity as the base class type instead of having to use a more specific subclass type. For example</p>
<pre class="brush: java;">
  String msg = &quot;Hi There &quot;+customer.getName();
</pre>
<p>is much cleaner than</p>
<pre class="brush: java;">
  String msg = &quot;Hi There &quot;;

  if (customer instanceof PersonCustomer) {
    msg = msg+((PersonCustomer)customer).getPerson.getPersonName();
  }

  if (customer instanceof CompanyCustomer) {
    msg = msg+((CompanyCustomer)customer).getCompany.getCompanyName();
  }
</pre>
<p>Another nice effect of this is modularity since you can add new customer types and the old queries will work the same way. For example, if you start with <code>PersonCustomer</code> you might have a query which lists the customers with a certain credit limit.</p>
<pre class="brush: java;">
select c from Customer c where c.creditLimit &gt; 500
</pre>
<p>If you suddenly add the <code>CompanyCustomer</code> class to the application, the query will still work and will now include company based customers in the list. Remember, the more attributes defined on the base class, the more attributes you will be able access or query on when obtaining instances as the base class. However, note that code driven attributes such as the <code>getName()</code> example above cannot be used for querying in JPA since the attribute does not resolve to a database field. To query by person name you would have to drop down to using the actual class name to query the name fields in the person reference. </p>
<h1>Unique People, non-unique references</h1>
<p>If an employee leaves the company and comes back, we can deal with this much easier because we can set the end date for the existing <code>Employee</code> instance when they leave and when they come back, we can create a new employee instance that references the same <code>Person</code> entity. We still only have one <code>Person</code> instance that is referenced by both <code>Employee</code> instances and thus there is no duplication. This kind of modeling is not only more accurate in that one person was an employee on two different occasions, but it also provides a form of auditing trail for that person. If you store the <code>Employee</code> reference, you can still use either the person or the employee id to search for data. If you wanted to see what orders this specific employee had filled in, you can search using either the employee id which would get the orders for this version of the employee only, or you could match based on the person id and see what orders that person had ever filled in as either employee instance. This also reflects the real world better since there is only ever one person, but they could have multiple periods as an employee. </p>
<h1>Modeling with JPA</h1>
<p>It is fairly easy to model the basic composition in JPA by adding a <code>@ManyToOne</code> annotation to the entity reference (in this case the person). </p>
<p>If you plan on creating subclasses that are backed by different entities (i.e. <code>PersonCustomer</code> and <code>CompanyCustomer</code>) then you have to choose between different inheritance strategies. If there only a few differences between subclasses, you can probably just use a single table. If there are bigger differences between the subclasses, you might want to use a joined table inheritance strategy while keeping the core attributes of the parent class in the main table. </p>
<p>For legacy databases, you could be faced with the problem that the referenced entity id, such as the company or person id in the customer subclass, is stored in the same field in the database record. You can use the same field name for the reference in the subclasses and JPA will work with it.</p>
<pre class="brush: java;">
public class PersonCustomer extends AbstractCustomer {

  @ManyToOne
  @JoinColumn(name=&quot;REF_ID&quot;)
  private Person person;

}

public class CompanyCustomer extends AbstractCustomer {

  @ManyToOne
  @JoinColumn(name=&quot;REF_ID&quot;)
  private Company company;

}
</pre>
<p>Obviously, this method eliminates the opportunity to use foreign keys since a foreign key cannot reference two different tables. New designs should not use this method for this reason even though JPA allows it. If you let JPA drop and create the tables for you, with Hibernate at least, you will end up with a foreign key on the <code>REF_ID</code> field to either the person or company table that will be incorrect when you assign the other subclass type to it. Through luck, it may not raise an error the first time around (if you happen to have an instance of one entity that has the same Id as the other entity type) but it will at some point.</p>
<p>If you really need this design, then you can just build the tables yourself without the foreign key, but you should use a separate field even though it means that each record will have blank field in it. With a separate or join table inheritance strategy, you have no choice but to use separate fields for the references.</p>
<h1>A technique with many uses</h1>
<p>This technique has many applications, but I haven&#8217;t really seen it discussed that much. Obviously, most published application examples (i.e. Pet store or my own Issue Tracker) are trivial or incomplete so they don&#8217;t really require this level of attention to modeling detail. However you start to find all sorts of places this technique can be used for larger domain models either to provide functionality needed now or a flexible design to meet future requirements. Obviously, we don&#8217;t want to use this for everything in case we want to extend any object in our model, but refactoring models once you have gone live can be problematic as it not only involves code refactoring, but database refactoring as well. Adopting this technique early (i.e. pre production) in places it is likely to be needed can save a lot of headaches later on.</p>
<p>As another example, let&#8217;s say you wanted to define a <code>Location</code> which is basically an address and a few other attributes. These locations can be used for all sorts of things in various places in the application. We already have an <code>Address</code> class used throughout our code and we can embed it in our <code>Location</code>.</p>
<pre class="brush: java;">
public class Location {

  @Embedded
  private Address address;

  private Date createdOn;
  private String description;

}
</pre>
<p>Half way through your project you find that since this location class is used everywhere, the needs have changed somewhat and in some places need to have a dynamic address that belongs to a person and needs to be updated when the persons address changes, and some places need a static fixed address that never changes (i.e. delivery address an order was sent to which never changes). </p>
<p>We can easily implement this by creating a <code>Location</code> class that is subclassed into the different implementations that source the address from different places.</p>
<pre class="brush: java;">

public abstract class Location {

  public Address getAddress();
  private String description;
  private Date createdOn;

}

public class FixedLocation extends Location {
  @Embedded
  private Address address;

  public Address getAddress() {
    return address;
  }
}

public class PersonLocation extends Location {

  @ManyToOne
  private Person person;

  public Address getAddress() {
    return person.getPrimaryAddress();
  }

}
</pre>
<p>Not only have we provided a solution for our fixed and dynamic address problem, since <code>FixedLocation</code> will store the address internally while the others will dynamically obtain the latest address from the <code>Person</code>, but we have provided a structure that will allow us to turn any entity into an address provider for our <code>Location</code> class. In some ways, we are using it as more of an adapter pattern since the address sources no longer have a common type. We are using an adapter pattern to make the different implementation sources fit with our <code>Location</code> interface.</p>
<p>I have found a number of uses for such compositions/adapters in places where inheritance would have severely limited my options or provided some difficult challenges,  and by implementing this concept I&#8217;ve been able to make my models far more flexible and be able to accommodate new needs quickly. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/article/using-composition-in-object-modeling/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Java EE 6 Is Here</title>
		<link>http://www.andygibson.net/blog/news/java-ee-6-is-here/</link>
		<comments>http://www.andygibson.net/blog/news/java-ee-6-is-here/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 00:13:19 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[CDI]]></category>
		<category><![CDATA[EJB]]></category>
		<category><![CDATA[Glassfish]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[Netbeans]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=689</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>Like Christmas come early, Sun <a href="http://www.sun.com/aboutsun/pr/2009-12/sunflash.20091210.1.xml">announced</a> 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.</p>
<p>Glassfish v3 which implements the full JEE 6 stack has also been released, with JBoss&#8217; 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.</p>
<p>Personally, I&#8217;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.</p>
<p>I&#8217;ll try and get some tutorials on developing with CDI and JSF 2.0 with Netbeans and Glassfish out soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/news/java-ee-6-is-here/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Glassfish, Netbeans and JSF 2.0 Test Drive</title>
		<link>http://www.andygibson.net/blog/article/glassfish-netbeans-and-jsf-2-0-test-drive/</link>
		<comments>http://www.andygibson.net/blog/article/glassfish-netbeans-and-jsf-2-0-test-drive/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 04:32:44 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[EJB]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Netbeans]]></category>
		<category><![CDATA[Seam]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=611</guid>
		<description><![CDATA[I&#8217;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.

(note This post relates to both the milestone 2 and [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;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.<br />
<span id="more-611"></span></p>
<p>(<b>note</b> This post relates to both the milestone 2 and beta versions of Netbeans 6.8 which I have been tinkering with over the duration of this article being written.)</p>
<p>The <a href="http://www.netbeans.org/community/releases/68/">download for Netbeans 6.8 </a> comes with <a href="https://glassfish.dev.java.net/">Glassfish v3 </a> which implements JEE 6 including <a href="http://jcp.org/en/jsr/detail?id=314">JSF 2.0</a> and <a href="http://jcp.org/en/jsr/detail?id=317">JPA 2.0</a>.</p>
<p>Glassfish now has <b>really</b> fast hot deployment so you can change a line of code, save it, and it re-deploys instantly which in my opinion, this is a huge productivity booster. This isn&#8217;t limited to Netbeans, the eclipse plugins also provide this feature, and it works with pretty much any framework. I tried it with Wicket and Spring MVC and it was fantastic to get a wicket error where I had forgotten to add a component, so I go back to the java page code, add the component, refresh my browser and it works. Glassfish now has support for JEE 6 so you can make a pojo a local EJB just by adding the <code>@stateless</code> annotation to it. You can also deploy EJBs in war files as well without needing the whole EAR setup. One problem I did see was that when you used the EAR project setup with an EJB and War project, the hot deploy didn&#8217;t appear to work as well. Changes to the war file didn&#8217;t appear to redeploy, maybe because it is the EAR file that is deployed and not the war. However, still fantastic stuff.</p>
<p>Netbeans 6.8 beta was released in the last week or so. Feature-wise it is a great product with better tooling for JSF, including JSF 2.0, facelets support, and auto-completion for JSF backing beans in the JSF page. It also includes support for JEE 6, EJB 3.1, JPA 2.0 and development with Glassfish v3. It also improves upon the existing Maven support by providing for mavenized Ear projects. </p>
<p>While the features are impressive, Netbeans still seems hindered by performance issues and some minor bugs (although it is a milestone/beta release). Personally, I found this release no more sluggish that other releases although some people in the forums have had worse experiences. Netbeans strength has always been that it offers one standard solution without the plugin nightmares that eclipse has. While Netbeans has plugins they are more like installable features, they have a higher granularity than Eclipse plugins which is more like DLL hell. That said, I use Eclipse at work and it is always hard to shift from one keyboard mapping to another, and Eclipse does seem faster without the intermittent pauses. However, right now, Netbeans is a superior product in terms of features, especially for a JSF developer. I&#8217;d keep an eye out for the 6.8 final release to see how it comes out, and give 6.8 milestone 2 a go just to enjoy the experience if you are interested in using a standards based stack because thats obviously where the Netbeans folks are focused. </p>
<p>One big issue I have with Netbeans is the oddness of some of the key mappings. I think in nearly every application I use I press Alt+F and then C to close the currently edited document. Whether is it in MS Office, Borland Delphi, Eclipse, Firefox, while in the file menu, the C key always closes the currently open document you are editing. In Netbeans, it closes the currently edited project which means suddenly my project disappears when I want to close an edited file. Another is the use of Ctrl+Space for invoking auto completion which in Netbeans sends focus to the project manager or something like that. Sure, I can change the keymappings, such as to the Eclipse profile, but then I&#8217;m using some arbitrary weird key mapping which isn&#8217;t Netbeans and it isn&#8217;t completely the same as Eclipse. It is probably this way for legacy reasons, but some of these key presses are de facto standards.</p>
<p>Lastly, we come to JSF 2.0 which was forged from JSF 1.2 and the litany of complaints about it. The JSR group looked at the solutions out in the wild that already work around those problems (many of which were written by people in that very group) and incorporates those fixes in a standard JSF API type of way. Primarily we have the dropping of JSP as the default view in exchange for the Facelets / JSF templating solution. This also lent itself very well to easier component creation including no-code components. There is now zero configuration required except for the servlet in <code>web.xml</code> and managed beans can now be defined using annotations. Navigation which also used to be in the <code>faces-config.xml</code> is also more convention of configuration. Another big request was the inclusion of AJAX awareness in the JSF lifecycle . It provides the bare minimum features that 3rd party developers can build upon using the standard API instead of their own AJAX solutions. There is better support for GET requests and page parameters as well as invoking actions on page requests which is a feature often used in Seam.<br />
There is also some performance boosts with regards to re-working state saving and the resource access mechanisms have been improved a great deal.</p>
<p>Also noteworthy is the inclusion of <a href="http://www.seamframework.org/Weld">Weld CR 1</a> which is the reference implementation of <a href="http://jcp.org/en/jsr/detail?id=299"> JSR 299 &#8211; Java Contexts and Dependency Injection </a> from JBoss. Admittedly, I haven&#8217;t really gotten round to taking a look at it, but from what I have seen and read so far, it looks like it fills some gaps in the JEE 6 platform and is up to par with the new found simplicity and strength that JEE 6 is promoting right now.</p>
<p>Overall, this is a pretty exciting set of tools and framworks and well worth a look if you are interested in adopting a standards based stack. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/article/glassfish-netbeans-and-jsf-2-0-test-drive/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing Multi-Maven Module Hibernate JPA Web apps</title>
		<link>http://www.andygibson.net/blog/links/writing-multi-maven-module-hibernate-jpa-web-apps/</link>
		<comments>http://www.andygibson.net/blog/links/writing-multi-maven-module-hibernate-jpa-web-apps/#comments</comments>
		<pubDate>Sat, 20 Jun 2009 22:46:52 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[Links]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[Maven]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=308</guid>
		<description><![CDATA[Here&#8217;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&#8217;d share them and if nothing else, I know where to find them the [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a couple of links regarding building <a href="http://today.java.net/pub/a/today/2007/03/01/building-web-applications-with-maven-2.html">Multi Module Apps</a> with the <a href="http://www.stripesbook.com/blog/index.php?/archives/34-Java-Persistence-Maven-2,-JPA,-and-Hibernate-Quickstart.html">Hibernate JPA Implementation</a>. 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&#8217;d share them and if nothing else, I know where to find them the next time I need them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/links/writing-multi-maven-module-hibernate-jpa-web-apps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Session Scoped Entities Locally in Seam</title>
		<link>http://www.andygibson.net/blog/article/using-session-scoped-entities-locally-in-seam/</link>
		<comments>http://www.andygibson.net/blog/article/using-session-scoped-entities-locally-in-seam/#comments</comments>
		<pubDate>Thu, 02 Oct 2008 01:12:28 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Journeyman]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[Seam]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=20</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>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 <code class="code">User</code> instance that is loaded when the user logs in and is outjected into the session scope. This <code>user</code> instance is available for the duration of the users session.<br />
<span id="more-20"></span><br />
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 <code >User</code> 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 <code>createdBy</code> property), then it might seem obvious to assign the <code>User</code> variable value to that value. However, the <code>User</code> is unmanaged by the entity manager for that conversation and will raise errors when you try and save the entity referencing the unmanaged <code>User</code>. </p>
<p>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&#8217;t want to have to write code to handle each property assignment or saving each entity type.</p>
<p>The answer is to have a locally scoped instance of the user that is generated from the session scoped instance. We create a new conversationally scoped bean which will hold the factory for the scoped user instance. The factory method takes the session scoped <code class="code">User</code> instance and merges it with the current entity<br />
manager to get a locally usable instance.</p>
<pre class="brush: java;">
@Name(&quot;scopedUserBean&quot;)
@Scope(ScopeType.CONVERSATION)
public class ScopedUserBean {

  @In
  private User user;  //injection point for session scoped user

  @In
  private EntityManager entityManager;  

  @Factory(&quot;scopedUser&quot;)
  public User getScopedUser() {
    return (User) entityManager.merge(user);
  }

}
</pre>
<p>Now, when we want to reference the user in locally scoped fashion, we can do so using the <code  class="code">scopedUser</code> variable. Note also that we can compare the instances either in the server side bean, or even in the JSF page. </p>
<pre class="brush: java;">
@Name(&quot;caseEditor&quot;)
@Scope(ScopeType.CONVERSATION)
public class CaseEditorBean{

  @In
  private User scopedUser;  

  @In
  private EntityManager entityManager;

  @In
  private Case case;  

  //we can compare scoped user to
  public void closeCase() {
    if (case.createdBy == scopedUser) {
      //this is the users case, they can close it
    } else {
      //this is not your case, you can't close it!
    }
  }

  public String saveCase() {
    case.createdBy = scopedUser;
    entityManager.persist(case);
  }
</pre>
<p>We can compare the instance on the case with the instance from scopedUser because they are the same instance in the same conversation, and even perform comparisons in EL expressions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/article/using-session-scoped-entities-locally-in-seam/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
