Hibernate/Struts2: Copy an object attributes to a new object

Here is the way I managed to copy an object attrbibutes to a brand new object:
public class AccountAction
{
    private Account account;
    private Long id;
    private Long id_NEW;
    
    public String copy()
    {
        String result = ERROR;
       
        if (getId() != null && account != null)
        {
            getHibernateSession().evict(account);
            Integer id_from_sequence = 1 + (Integer)getHibernateSession().createSQLQuery(“select id from account_seq for update”).uniqueResult();
            getHibernateSession().createSQLQuery(“update account_seq set id = ” + id_from_sequence).executeUpdate();
            account.setId(id_from_sequence.longValue());
            account.setCreation(new Date());
            account.setSend(null);
            account.setStatus(Status.NEWACCOUNT);
            getHibernateSession().save(account);
            setId(id_from_sequence.longValue());
            result = “inputAfterCopy”;
        }
       
        return result;
    }
}

struts.xml:

<action name=”Account” class=”fr.package.AccountAction”>
    <result name=”input”>/WEB-INF/pages/account_input.jsp</result>
    <result name=”inputAfterCopy” type=”redirectAction”>
        <param name=”id”>${id_NEW}</param>
        <param name=”actionName”>Account!input</param>
    </result>
</action>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: