[jbossseam-issues] [JBoss JIRA] Commented: (JBSEAM-4057) Add static method EntityHome.wrapInstance and add location for update/persist processing

Valerie Griffin (JIRA) jira-events at lists.jboss.org
Mon Mar 30 17:48:22 EDT 2009

    [ https://jira.jboss.org/jira/browse/JBSEAM-4057?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12459745#action_12459745 ] 

Valerie Griffin commented on JBSEAM-4057:

Actually, there are several things included in this request. I think each of them chould be implemented. I grouped them because the code to implement them is all in the same module.


Sometimes, my code creates an Entity that needs to be saved or updated in the database. The cleanest way to save this Entity is to create an EntityHome around it. Sometimes, multiple related Entity objects are created and saved as part of a single action. Other times, I've copied a list of objects related to one Entity to have a similar relationship to a different Entity. These objects cannot always be saved by cascading them.

Originally, I had created the EntityHome objects using its parameterless constructor. Then, I attached the Entity to that object. It didn't completely work  From forum comments, I'm not the only person who tried to create EntityHome objects this way, so adding the function would save others from the missteps I made. I'm found the Component.getInstance method, which I'm using here, in response to a forum comment.

update/persist catch InvalidStateException instances

This makes it possible to see hibernate validation errors that are caught on persist and update as messages. This is especially useful for fields that are not initialized by the GUI. I didn't put corresponding remove code into the source, but I think it would be useful.

Other changes to update/persist

It's really an error if the instance is null on an update or persist and should be treated as such.

It's often useful to know where to insert code for pre- or post-processing, especially when some people on the team don't initially know where to put the code.

> Add static method EntityHome.wrapInstance and add location for update/persist processing
> ----------------------------------------------------------------------------------------
>                 Key: JBSEAM-4057
>                 URL: https://jira.jboss.org/jira/browse/JBSEAM-4057
>             Project: Seam
>          Issue Type: Feature Request
>          Components: Tools
>    Affects Versions: 2.1.1.GA
>         Environment: Any
>            Reporter: Valerie Griffin
>         Attachments: EntityHome.java.ftl
> Constructing an EntityHome object really doesn't provide a completely-initialized object. I needed to create EntityHome objects around existing @Entity objects. Once created, these objects can be saved in the database. I created a new static method in the code generated by EntityHome. It's called wrapInstance and , in use, is defined as:
> static public MyTblHome wrapInstance(MyTbl dat);
> If there's an id in the MyTbl instance, it is used. Otherwise, an id is created and used.
> I also changed update and persist:
> If we get there with a null instance, it's an error so we return "invalid".
> There are commented locations for pre- and post-update code. For example, the code can automatically save the ID of the user performing an update.
> There's a catch for validation errors (hibernate InvalidStateException instances). If one is found, all InvalidValue lines are logged and captured foe message output.

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the seam-issues mailing list