Skip to main content

Unable to update data using Hibernate + Glassfish

13 replies [Last post]
rpatel
Offline
Joined: 2003-08-13

Hello,

I am using Hibernate persistence provider (3.3.1 GA) on Glassfish (Update 2). The database is Oracle XE. This is a JSF application where the managed bean is using application managed extended scoped persistence context to access database.

Even though I am able to view the data, I am not able to change it. It is quite strange. I can see the SQL generated by the provider, and interestingly there are no update/insert statements generated when I change or insert an existing or new entity. No exceptions.

Does anyone have any ideas I can pursue further? Is there a known bug in this regard?

P.s. If you think that configuring Hibernate provider on Glassfish could be an issue, know that I do not see anything strange going on in the domain's log file. Basically, I just copied the right jars from Hibernate core and Hibernate Entity Manager to the Glassfish lib folder. Nothing exceptional there.

Thanks a lot,
Rima.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rpatel
Offline
Joined: 2003-08-13

Sahoo,

I thought that you'd like to know about this in the JPA spec. Under 5.7, I found the following:

"When a JTA application-managed entity manager is used, if the entity manager is created outside the scope of the current JTA transaction, it is the responsibility of the application to associate the entity manager with the transaction (if desired) by calling EntityManager.joinTransaction."

Not sure if this can be construed as:

When a JTA application-managed entity manager is used, if the entity manager is created outside the scope of the current JTA transaction, the provider [b]will not[/b] associate entity manager with the transaction without a call to EntityManager.joinTransaction.

Regards,
Rima.

Sahoo

Hi Rima,

Yes, I am aware of those wordings. They don't cover the scenario you
have come across. Not sure, why the spec authors did not clearly cover
that scenario. Although I agree with you as far the intention of the
spec goes, I think your interpretation can be challenged.

Thanks,
Sahoo

glassfish@javadesktop.org wrote:
> Sahoo,
>
> I thought that you'd like to know about this in the JPA spec. Under 5.7, I found the following:
>
> "When a JTA application-managed entity manager is used, if the entity manager is created outside the scope of the current JTA transaction, it is the responsibility of the application to associate the entity manager with the transaction (if desired) by calling EntityManager.joinTransaction."
>
> Not sure if this can be construed as:
>
> When a JTA application-managed entity manager is used, if the entity manager is created outside the scope of the current JTA transaction, the provider [b]will not[/b] associate entity manager with the transaction without a call to EntityManager.joinTransaction.
>
> Regards,
> Rima.
> [Message sent by forum member 'rpatel' (rpatel)]
>
> http://forums.java.net/jive/thread.jspa?messageID=223536
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

Alexis Moussine-Pouchkine

Hello Sahoo, Rima,
I truly believe you should file a bug.
Whatever the outcome, it'll be more easy to trace
for other people facing this very same issue.
thanks,
-Alexis

Sahoo a écrit :
> Hi Rima,
>
> Yes, I am aware of those wordings. They don't cover the scenario you
> have come across. Not sure, why the spec authors did not clearly cover
> that scenario. Although I agree with you as far the intention of the
> spec goes, I think your interpretation can be challenged.
>
> Thanks,
> Sahoo
>
> glassfish@javadesktop.org wrote:
>> Sahoo,
>>
>> I thought that you'd like to know about this in the JPA spec. Under
>> 5.7, I found the following:
>>
>> "When a JTA application-managed entity manager is used, if the entity
>> manager is created outside the scope of the current JTA transaction,
>> it is the responsibility of the application to associate the entity
>> manager with the transaction (if desired) by calling
>> EntityManager.joinTransaction."
>>
>> Not sure if this can be construed as:
>>
>> When a JTA application-managed entity manager is used, if the entity
>> manager is created outside the scope of the current JTA transaction,
>> the provider [b]will not[/b] associate entity manager with the
>> transaction without a call to EntityManager.joinTransaction.
>>
>> Regards,
>> Rima.
>> [Message sent by forum member 'rpatel' (rpatel)]
>>
>> http://forums.java.net/jive/thread.jspa?messageID=223536
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
>> For additional commands, e-mail: users-help@glassfish.dev.java.net
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

Sahoo

Hi Rima,

This looks like a bug to me, but there is an argument against it as
well. The spec does not prohibit a provider to automatically attach to
an existing transaction. In any case, you should file one in GlassFish
entity-persistence category.

Thanks,
Sahoo

Sahoo wrote:
> Yes, send it.
>
> -- Sahoo
>
> glassfish@javadesktop.org wrote:
>> Sahoo,
>>
>> Btw, do let me know if you want me to send you the NB project so that
>> you can check it at your end.
>>
>> Regards,
>> Rima.
>> [Message sent by forum member 'rpatel' (rpatel)]
>>
>> http://forums.java.net/jive/thread.jspa?messageID=223427
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
>> For additional commands, e-mail: users-help@glassfish.dev.java.net
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

rpatel
Offline
Joined: 2003-08-13

Hello Sahoo,

I am looking at the spec as we speak to see if there is anything in it that clearly prohibits doing so. However, the method joinTransaction() on EM does tell us something about the intention of the spec writers. They, most probably, didn't want an application managed EM to be automatically bound to an ongoing transaction when such an EM is created outside of the transaction's scope. Hence, the joinTransaction() API.

Anyway, I am sending an email to Linda DeMichiel and Marina Vatkina to see what they have to say, before I go ahead and file a bug.

Thanks for all your help on this.

Regards,
Rima.

ss141213
Offline
Joined: 2005-03-30

How are you committing the transaction? How are you associating the extended PC with the transaction?

-- Sahoo

rpatel
Offline
Joined: 2003-08-13

Sahoo,

Your question did the magic because it made me ask myself the right question. So here is the short version of the story - there are possible bugs in NB 5.5 and TopLink Essentials. Hibernate actually behaves as it should, IMHO.

[u][b]What I was trying to do[/b][/u]

I used NB 5.5 wizard to generate JSF classes from entities. NB 5.5 generates the JSF managed bean (controller class is what they call it) for each entity. So for my entity, NewsEntity, there is a NewsEntityController. Now NewsEntityController injects a UserTransaction. And, in the create(), edit(), and destroy() handlers NB wizard generates code with the begin() and commit() demarcations to take care of changes. For instance, below is the code that gets generated for create() in the NewsEntityController-

public string create() {

// Gets application-managed extended scoped EM
EntityManager em = getEntityManager();

try {
utx.begin();
em.persist(newsEntity);
utx.commit();
} catch (Exception ex) {
...
}
return "newsEntity_list";
}

[u][b]What is wrong with the above?[/b][/u]

The problem in the code above is that someone forgot to put em.joinTransaction() call in it. EM is created outside of an active transaction, so it needs to be told about the active transaction. NB team needs to fix the "JSF from entity classes" wizard so that it generates the correct code.

[u][b]TopLink's weird behavior[/b][/u]

I think one of the reasons why I was led astray in troubleshooting is because NB generated code works just fine for TopLink Essentials. I have no idea why TLE works. It should not, don't you think? TLE is flushing the state of entities in an EM that has not been associated with the active transaction. Why should it do so? I would really like to hear your thoughts on this.

[u][b]Conclusion[/b][/u]

I modified the NB 5.5 generated code to add em.joinTransaction() right after utx.begin(). And, that makes the inserts/updates work on Hibernate as expected. I will go ahead and file a bug with NB 5.5 in the meantime.

Regards,
Rima.

ss141213
Offline
Joined: 2005-03-30

Hi Rima,

I am glad that my questions helped you solve your issue. I can't see anything wrong in TLE flushing the changes to the database. As long as the changes are [b]not[/b] committed, it's OK, isn't it? Can you check if the transaction is actually committed or not when you use TLE? If TopLink is automatically associating the extended PC with the transaction and hence it is committing the changes, then I expect that to be a bug.

Thanks,
Sahoo

rpatel
Offline
Joined: 2003-08-13

Hello Sahoo,

By "flushing" I did mean to say that it commits changes to the database. So it does seem that TLE is associating the application managed PC automatically with the active transaction.

Thanks for your prompt responses, and regards,
Rima.

rpatel
Offline
Joined: 2003-08-13

Sahoo,

Btw, do let me know if you want me to send you the NB project so that you can check it at your end.

Regards,
Rima.

Sahoo

Yes, send it.

-- Sahoo

glassfish@javadesktop.org wrote:
> Sahoo,
>
> Btw, do let me know if you want me to send you the NB project so that you can check it at your end.
>
> Regards,
> Rima.
> [Message sent by forum member 'rpatel' (rpatel)]
>
> http://forums.java.net/jive/thread.jspa?messageID=223427
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

rpatel
Offline
Joined: 2003-08-13

Sahoo,

Sending it to your Sun email.

Regards,
Rima.

rpatel
Offline
Joined: 2003-08-13

Bumping the thread...

Folks, any pointers are appreciated, since I am stuck with this one. I have already posted this question to Hibernate.org forums, without any luck as yet.

Regards,
Rima.