[jboss-user] [JBoss Seam] - Seam Hibernate Q

tony.herstell@gmail.com do-not-reply at jboss.com
Wed May 9 07:41:47 EDT 2007


Background
After a lot of poking around with log4j I can now see the hibernate debug comments (as the exceptions are telling me very little other than Advert was invalid!)

After trapping the validation failure exception in Eclipse and looking at the message (as it really wasnt being put out by seam) it turned out that I had a 
@Length 30
for an ENUM which it (Seam) really didn't like!
Its quite exciting to see what Seam persists in the Database for the Enum!

  |     public enum AdvertType {
  |         Lineage  ("label_ad_type_lineage"),
  |         BannerAd ("label_ad_type_banner_ad");
  |         private final String label;
  |         AdvertType(String label) {
  |             this.label = label;
  |         }
  |         public String getLabel() { return label; }
  |     }
  | 

Bug
Anyhow, this got me futher to persisting my object... which brings me to:

I have a servies of things I expose to the client; that they can attatch to the object tree of my new object.
These have been read in before into a session scoped seam bean so I assume they are detached!
How do I manage to persist my object with these "hangers on"...


  |     /**
  |      * Utiltiy method to actually persist the Campaign.
  |      * TODO More error handling...
  |      */
  |     @TransactionAttribute(TransactionAttributeType.REQUIRED)
  |     private void save() {
  |         User currentUser = (User)em.createQuery("from User u where u.username = :username")
  |         .setParameter("username", Identity.instance().getUsername())
  |             .getSingleResult();
  |         advertisingCampaign.setAdvertiser(currentUser);
  |         // The targeting categoires are detached, I need to re-attatch them.
  |         em.merge(advertisingCampaign);
  |         em.persist(advertisingCampaign);
  |     }
  | 

I am guessing merge and then persist but Hiberante does not like this.

When I enter the merge I have (In a LinkedHashSet):
[Category (Id => 0, Version => 0, Name Key (inl8) => category_everything, MaintenanceDates --> MaintenanceDates, Date Effective From => 9/05/2007, Date Effective To => null), Adminsitration --> Administration, Creation Date => 9/05/2007))]

But by the time the exception happens this has gone to null.

Any suggestions? I think I am doing this completely wrong.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4044247#4044247

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4044247



More information about the jboss-user mailing list