Evolutionary Dawn

March 21, 2008

Migrating from JBoss to Glassfish

Filed under: Uncategorized — admin @ 9:22 am

I recently migrated a J2EE application from JBoss 4.0.4-GA to Glassfish and experienced a number of different issues.

In this post I will describe the issues and the solutions to them in the hopes that it will help solve others headaches.

Issue #1 JBoss EJBQL != Glassfish(J2EE Spec) EJBQL

Take for example the following EJBQL that will function under JBoss:

“select object(s) from Slab as s where s.branch =”+branch;

Does not work properly under Glassfish unless (I believe, but not tested) you @Override the equals(Object) method

in your persistent entities.

A simple work around for those of us that are LAZY and do not feel like @Overriding all of those equals(Object) methods is to change your EJBQL to something like the following:

“select object(s) from Slab as s where s.branch.id =”+branch.getId();

Issue #2 Embeddable objects some how get referenced to Entities in the Glassfish Cache

To be honest I think this is a horrible feature of Glassfish but by no means am I going to spend the time to try

to change the Glassfish developer communities mind on it (And it could just be J2EE spec).

Take for instance the following Object Model:

1
2
3
4
5
6
7
8
9
10
11
@Entity
public class Customer implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
        private Long id;
    @Column(name="c_name")
    private String name;
    @Embedded
    private Address address;
    //Magical get/set methods here
}
1
2
3
4
5
6
7
8
9
10
@Embeddable
public class Address implements Serializable {
    private String streetLineOne;
    private String streetLineTwo;
    private String city;
    private String state;
    private String postalCode;
    private String country;
    //Magical get/set methods here
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
@Entity
@Table(name="belt_order_header")
public class OrderHeader implements Serializable {
 
    public enum OrderStatus { BID, ORDER, INVOICE, HOLD, CONSIGNMENT }
 
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private Long id;
    private OrderStatus status;
    private String poNumber;
    private String internalNotes;
    private ShipVia shipVia;
    @Embedded
    @AttributeOverrides( {
        //Magical Overrides
    } )
    private Address billTo;
    @Embedded
    @AttributeOverrides( {
        //Magical Overrides
    } )
    private Address shipTo;
 
    @ManyToOne private Customer customer;
    @ManyToOne private Branch billingBranch;
    @ManyToOne private Branch fabricationBranch;
     //Magical get/set methods here
}

If I were to try the following in a Session Bean:

1
2
3
4
5
6
7
public OrderHeader createOrderHeader(Customer customer) {
    OrderHeader oh = new OrderHeader();
    oh.setBillTo(customer.getAddress());
    oh.setShipTo(customer.getAddress());
    em.persist(oh);
    return oh;
}

It would throw some narly unreadable and annoying Exception. The reason you ask? It happens because

the PersistentContext has associated the Address object to the Customer.

The work around is to create in the Address object a static method that copies the attributes

from one Address object to a new one. Like the following:

1
2
3
4
5
6
7
8
9
10
public static Address copy(final Address address) {
    Address copy = new Address();
    copy.setStreetLineOne(address.getStreetLineOne());
    copy.setStreetLineTwo(address.getStreetLineTwo());
    copy.setCity(address.getCity());
    copy.setState(address.getState());
    copy.setCountry(address.getCountry());
    copy.setPostalCode(address.getPostalCode());
    return copy;
}

And redo the OrderHeader method as such:

1
2
3
4
5
6
7
public OrderHeader createOrderHeader(Customer customer) {
    OrderHeader oh = new OrderHeader();
    oh.setBillTo(Address.copy(customer.getAddress()));
    oh.setShipTo(Address.copy(customer.getAddress()));
    em.persist(oh);
    return oh;
}

Issue #3 Once again the GlassFish cache

Since there is a great article on this I will just link it. Just remember REFRESH, REFRESH, REFRESH!

http://weblogs.java.net/blog/guruwons/archive/2006/09/understanding_t_1.html

Here is a example of what I mean:

1
2
3
4
5
6
7
8
9
10
11
12
13
public BeltType find(Object pk) {
    BeltType beltType = (BeltType) em.find(BeltType.class, pk);
    try {
        em.refresh(beltType);
    }
    catch(EntityNotFoundException ex) {
        return null;
    }
    if(beltType == null)
        return null;
    loadLazyInitializations(beltType);
    return beltType;
}

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

You must be logged in to post a comment.

Powered by WordPress

  • la ink upcoming episodes
  • la ink members
  • new england patriots underwear
  • zara phillips school
  • editor
  • c span video contest
  • xanadu bengals
  • chicago bears expo
  • mtv 90s music videos
  • commons
  • la ink 105
  • tea party young people
  • tea party medicare
  • greg olsen university of miami
  • search engines rankings 2011
  • la ink 03x05
  • battleship kirishima
  • chad ochocinco nascar
  • greg olsen boulder
  • bengals games
  • chicago bears gifts
  • dis x
  • battleship classes
  • bengals andy dalton
  • freida pinto zac posen
  • bea zuberbühler
  • kush
  • connecticut 104.1
  • cspan journal
  • recievers
  • chad ochocinco parents
  • vince young dadvince young eagles
  • reply
  • search engines for kids
  • greg olsen website
  • tea party hobbits
  • bea nipa
  • vince young depression
  • connecticut sun
  • ebook
  • battleship aurora
  • randy moss korey stringer
  • collect
  • new england patriots jake locker
  • new england patriots 80
  • payroll
  • 4pm cspancspan area 51cspan 90.1
  • la ink tattoos
  • tea party ribbons
  • bengals cheerleaders tryouts 2011
  • chad ochocinco yesterday
  • bea oracle
  • search protocol host
  • connecticut juvenile training schoolconnecticut kids
  • searchbugsearch engines
  • suppression
  • greg olsen dustin keller
  • new england patriots 07
  • vince young 99 yard video
  • playstation2
  • popeyes
  • pounds
  • very
  • search engines for jobs
  • hp support contact number
  • search vim
  • cosco
  • hp support 6310hp support 7200
  • search engines internet
  • search 2.0
  • la ink ink
  • randy moss bio
  • standards
  • maid
  • stryker
  • search xml file
  • new england patriots gillette stadium
  • vince young usc
  • la ink season 5 premiere
  • hp support chat
  • search 4
  • connecticut football
  • login
  • search jail inmates
  • hp support 6930p
  • vince young rivals
  • cspan kucinich
  • cspan washington correspondents dinner 2011
  • di's hallmark
  • bea 460 bosch
  • randy moss 98 vikings
  • rancher
  • lowrider
  • hp support center
  • bea verdi
  • connecticut 30 news
  • sketches
  • bengals forum
  • c span ii
  • vince young jay cutler
  • vince young redskins
  • freida pinto jeansfreida pinto kissing
  • zara phillips husband
  • connecticut 5th district
  • hp support error 1005
  • la ink youtube pixie
  • new england patriots 4
  • c span yesterdayc span zelaya
  • search engines questions
  • connecticut 97.7connecticut attorney general
  • vince young status
  • bengals job fair
  • hp support greece
  • hp support helpline
  • bengals 09 record
  • bengals youth jerseys
  • bengals xxiii
  • dis windsor wi
  • bengals new uniforms 2012
  • labs
  • largest
  • kenworth
  • randy moss university
  • bea exhibitors
  • chicago bears 96
  • cspan question timecspan radio
  • search engines usage statistics 2010
  • search engines for jobs
  • bengals hard knocks episode 1
  • bengals 09
  • cspan streaming
  • vince young uncle rico gif
  • dis 0 0.9
  • bea luna
  • chad ochocinco sisterchad ochocinco twitter
  • randy moss wallpaper
  • vince young football camp
  • chad ochocinco yesterday
  • dis lyrics
  • c span shelby foote
  • martins
  • hp support id
  • vince young jersey texas
  • search and seizure
  • tea party zombies download
  • helios
  • duluth
  • hp support center
  • randy moss combine results
  • mtv dougie
  • connecticut limo
  • zara phillips kids
  • backup
  • cspan michelle bachmann
  • connecticut law tribune
  • new england patriots 1997 roster
  • bengals tryouts
  • instalation
  • hp support 6500a plus
  • radius
  • evergreen
  • vince young released
  • bandera
  • search 3 bodybuilding other index
  • new england patriots offense
  • randy moss football cards
  • chad ochocinco to detroit
  • tea party agenda
  • tea party obama
  • airgun
  • randy moss autograph
  • dist 91
  • mtv music awards
  • chattanooga
  • freida pinto can't act
  • mtv american idol
  • armor
  • inflatable
  • aveo
  • wetsuit
  • randy moss 07 08 highlights
  • hp support quick test pro