EJB3: When do Entities get detached in practice?

Hi,
I am currently improving my first EJB3 / JSF prototype in order to get a good feeling for that new technology. I am using Sun Appserver 9, NetBeans 5.5.
I have the followiong design-setup:
JSF-BackingBean ===uses===> @Remote Stateless Session Bean ===fetches==> EntityBeans
The general question is: 1.) Where do EntityBeans get detached in a JSF setup and 2.) does detaching mean, that I cannot traverse the relations anymore, even if I have eager fetching configured`?
Let me also ask some more detailed questions:
The Backing Bean stores the Entity Bean "A" in an attribute. So far so good. My Entity A has a 1:n association to Entity B with eager fetching configured in the annotation. When I now want to access the relation getBs() from within a JSF forEach statement, I keep getting an error from the persistence layer.
I found out, that if my Stateless Session Bean accesses getBs() after having retrieved A before it returns, then it works also from the JSF page. From my current understanding, eager fetching should have had the same effect....???!!!
Anyway, I read the EJB persistence specs and in chapter 5.6.3 it says, that:
Propagation of persistence contexts only applies within a local
environment. Persistence contexts are not propagated to remote tiers.Does this mean, that Entities get detached at this point? But why does it then work even remotely, when I access getBs() from the SLSB?
Furthermore, if I used a Local Interface for the SLSB, can I then expect this to work without the call to getBs()?
Would it have an impact to inject an EntityManager into the BackingBean? From my current understanding, container-managed transactions are demarcated through the SLSB, so the transaction would end there anyway, so I suppose injecting the EntityManager into the BackingBean does NOT have an impact. Can anybody confirm this?
Many Thanks in advance,
Stephan

Hi,
Hi Stephan. Great questions. Answers inline.
I am currently improving my first EJB3 / JSF
prototype in order to get a good feeling for that new
technology. I am using Sun Appserver 9, NetBeans
5.5.
I have the followiong design-setup:
JSF-BackingBean ===uses===> @Remote Stateless Session
Bean ===fetches==> EntityBeans
The general question is: 1.) Where do EntityBeans get
detached in a JSF setup It's independent of JSF itself. The detaching behavior depends on what kind of interface (local vs. remote) is used to access the Stateless Session bean and what the transactional settings are for the invocation. First off, any Java Persitence API entities passed through a Remote interface become detached when received by the caller, even if the caller is in the same application as the callee.
If the related entities were not fetched before the detachment, they will not be available after detachment.
If you use a Local interface to access the Stateless Session Bean, detachment will occur when the transaction within which the entities were fetched commits or rolls back. My guess is you're using the default tx behavior (CMT/TX_REQUIRED) for the SLSB business method and not demarcating transactions in the JSF bean, so the entities will become attached when the SLSB method returns.
and 2.) does detaching mean,
that I cannot traverse the relations anymore, even if
I have eager fetching configured`?You can try traversing afterwards but there's no guarantee the requested
entities will be there. If they happened to have been fetched before
the detachment, they will be returned. Otherwise, they won't be found and
since the entities are no longer associated with an entity manager, it's too
late for them to be fetched.
>
Let me also ask some more detailed questions:
The Backing Bean stores the Entity Bean "A" in an
attribute. So far so good. My Entity A has a 1:n
association to Entity B with eager fetching
configured in the annotation. When I now want to
access the relation getBs() from within a JSF forEach
statement, I keep getting an error from the
persistence layer.
I found out, that if my Stateless Session Bean
accesses getBs() after having retrieved A before it
returns, then it works also from the JSF page. From
my current understanding, eager fetching should have
had the same effect....???!!!That only applies to a managed entity. When it's in the
detached state, the eager fetching doesn't apply since
it's not associated with an EntityManager.
Anyway, I read the EJB persistence specs and in
chapter 5.6.3 it says, that:
Propagation of persistence contexts only applieswithin a local
environment. Persistence contexts are not propagatedto remote tiers.Persistence context propagation refers to the case where
two different Java EE components within the same transaction both access a
container-managed transactional EntityManager. If both components are within
the same application and running on the same JVM, they will "see" the same
persistence context. This is magic performed by the container to preserve
the transactional semantics from the Entity Bean model in J2EE 1.4 and earlier.
E.g, if your JSF bean had a container-managed entity manager and started
a global transaction, then invoked a Stateless Session Bean method with
TX_REQUIRED, the JSF bean's EntityManager would have the same
state as the Stateless Session Bean's EntityManager, without having to explicitly
pass references to entity classes between them.
>
Furthermore, if I used a Local Interface for the
SLSB, can I then expect this to work without the call
to getBs()? Only if you start a global transaction before invoking the SLSB and call
getBs() before committing the tx.
Would it have an impact to inject an EntityManager
into the BackingBean? Yes, that's one way to do it, but you also need to ensure that the same tx is being used. See below.
From my current understanding,
container-managed transactions are demarcated through
the SLSB, so the transaction would end there anyway,It depends on which transaction attribute is used. For the default tx attribute (TX_REQUIRED), if there is an existing transaction when the SLSB is accessed that will be used instead of the container starting a new one, which means it will not be committed by the container when the SLSB method returns.
so I suppose injecting the EntityManager into the
BackingBean does NOT have an impact. Can anybody
confirm this?Not true. See above. There's a good JavaOne talk on the topic of web-tier use of the Java Persistence API given by Linda Demichiel, Gavin King, and Craig McClanahan.
You can find it here :
http://developers.sun.com/learning/javaoneonline/2006/webtier/TS-1887.html
--ken
>
Many Thanks in advance,
Stephan

Similar Messages

  • Stop auto-creation of Assoc when creating Entities

    How can we stop auto-creation of Assoc files when creating Entities?

    Hi Varshal,
    Thanks for the suggestion.
    However, we thought of an alternate method that does involve changing the customers existing business process.
    1) Change the field AUDISP in the network profile to 1 "Never" for the conversion.
    2) Migrate the data. Program will create Networks, Activities & Components with the field AUDISP set to "Never create Reservation or Purchase Requisition".
    3) Change the field in AUDISP in the network profile back to "2 From Release".
    We will have to get the users to clean-up their data (close outstanding PRs or convert those PRs to POs) before this exercise for a clean cut-over.

  • Still not received my tablet as yet ad would like to know when I will get it

    my home phone No is [redacted]  and since i have had that number and my broadband and tv i have no received my tablet and would like to know when i will get it as it has been over 3 months since i signed up with you
    [mod edit: please do not post personal information such as phone numbers on the public board. Thanks!]

    Hi, 
    This is a customer forum so you will need to keep chasing EE on 150 about this issue. If you want to complain then please follow the EE process: http://ee.co.uk/help/safety-and-security/my-digital-life/complaints-code-of-practice
    Thanks, 

  • Do deleted entities get added to the validation listener?

    Hi all,
    I was reading about the 3 listeners in Jobinesh's [blog post|http://jobinesh.blogspot.com/2011/09/what-you-may-need-to-know-about.html] and got a doubt.
    i. Do deleted entities get added to the validation listener? Does not make sense to me as there would be no validations to trigger on deleted entities.
    ii. Is there some way to remove entities from Validation Listener? I see that there are method to remove the entities from other two listeners.
    Thanks,
    Srini

    Hi Frank,
    Was testing this and was surprised to find that validation listeners were not affected when I deleted entities. Maybe I missed something.
    If they get added, is there some way of removing the entity from the validation listener?
    Thanks,
    Srini

  • When does d4s get added to the list of camera that can tether on Lightroom

    when does d4s get added to the list of camera that can tether on Lightroom 5?

    Well, I got very tired of waiting for Adobe to support my Nikons so I use a Camranger, their computer and tablet app and tether wirelessly to LR. Yes, there is a bit of a delay amounting to a few seconds but in practice my customers love it and have not complained. I use the few seconds to better connect with them, answer questions, etc. Being wireless gives me more range of movement and I have one less cord. The Camranger goes in an old phone holster that clips to my shirt or pants pocket, connected by a 3 ft cord.
    You need to enable auto import in LR and point it to the folder that Camranger saves the files to. Since it is an import you can use presets if you wish. I've not seen a downside yet and Camranger has support for new cameras very quick like. An added plus is having full wireless functionality for your camera via the Camranger apps. You can change any setting, focus, use live view, etc.. using a phone, tablet or laptop.

  • My ITunes got corrupted and I kept getting a message when updating iTunes64msi missing so I uninstalled all files and I thought I removed all registry values but  when reinstalling I get an older version is installed and cannot be removed. I need a soluti

    My ITunes got corrupted and I kept getting a message when updating iTunes64msi missing so I uninstalled all files and I thought I removed all registry values but  when reinstalling I get an older version is installed and cannot be removed. I need a solution.

    (1) Download the Windows Installer CleanUp utility installer file (msicuu2.exe) from the following Major Geeks page (use one of the links under the "DOWNLOAD LOCATIONS" thingy on the Major Geeks page):
    http://majorgeeks.com/download.php?det=4459
    (2) Doubleclick the msicuu2.exe file and follow the prompts to install the Windows Installer CleanUp utility. (If you're on a Windows Vista or Windows 7 system and you get a Code 800A0046 error message when doubleclicking the msicuu2.exe file, try instead right-clicking on the msicuu2.exe file and selecting "Run as administrator".)
    (3) In your Start menu click All Programs and then click Windows Install Clean Up. The Windows Installer CleanUp utility window appears, listing software that is currently installed on your computer.
    (4) In the list of programs that appears in CleanUp, select any Bonjour entries and click "Remove", as per the following screenshot:
    (5) Quit out of CleanUp, restart the PC and try another iTunes install. Does it go through properly this time?

  • I am experiencing some major problems with my MacBook Pro. I have had some issues with it turning on/off at random times, but today, when starting, I get the grey start-up screen and a recovery bar. After filling in approx 1/4 of the way, the machine dies

    I am experiencing some major problems with my MacBook Pro. I have had some issues with it turning on/off at random times, but today, when starting, I get the grey start-up screen and a recovery bar. After filling in approx 1/4 of the way, the machine dies. After starting it in recovery mode, it will not allow me to download OS X Mavericks- it says the disk is locked. Any ideas? I do not have a back-up and do not want to erase everything before I have explored my options. Help?

    try forcing internet recover, hold 3 keys - command, option, r - you should see a spinning globe
    most people will tell you to do both pram and smc resets (google) and if you still have issues, either clean install (easy) or troubleshoot (hard)

  • Cancelled contract lines are populating in the SR form's subject tab when clicking on 'Get Contracts' button

    Cancelled contract lines are populating in the SR form's subject tab when clicking on 'Get Contracts' button. But user says, it should not be populated. What could be the reason? Please suggest.
    I have told the user :
    "In the case of a renewed contract, if the service request is logged during the effectivity of the original contract (which is now Expired), the original contract will be retrieved. If the service request is logged during the effectivity of the renewal contract then only the renewal contract will be retrieved.
      Contract Entitlement on Subject tab is based on Contract Start and End dates. All the contracts i.e. expired, active, cancelled will appear until the end date. As we can see the contract ES-10165 is end dated on 09-DEC-2014, hence it will appear on the subject tab as per the functionality."
    But the User is saying:
    "Contract coverage is clear to be based on dates, and that is quite clear to me as well… the problem comes with the different statuses.
    A SR can be associated to an “EXPIRED” contract line because the SR creation date could be falling between coverage line start and end dates, but can never be related to a “CANCELLED” line.
    This “CANCELLED” status means that the line is not valid for the contract, so if it is not valid for a contract, it is not valid for referencing a job…and this is only creating wrong costs associations."

    Hi Sudhakar,
    Drop inline message components for each of the textFields and the textArea and then run the application. You could also use a message list component but inline message components for each of the input components would give you a clear idea if any errors are occuring. In case any such errors are indeed occuring then the situation can be analysed further.
    Hope this helps
    Cheers
    Giri :-)

  • Upgraded to 5.4 when opening lightroom get a message "encountered an error when reading from its preview cache and need to quite" tried this several time but get the same eror message

    Upgraded to 5.4 when opening lightroom get a message "encountered an error when reading from its preview cache and need to quite" tried this several time but get the same error message.  Says Lightroom will attempt to fix the problem the next time it launches but that is not happening.  How do it fix this?

    Delete the preview cache using your operating system. It is a folder whose name ends with Previews.LRDATA. Do not delete the Lightroom catalog, which ends with .LRCAT

  • I have a gmail account set up on my macbook pro. One mail I sent with photos continues to repeatedly downloaded in Recovery. At the same time my Gmail won't download new emails into Inbox when I press Get New Mail. Help

    I have a gmail account set up on my mac. A few days ago I sent an email with photos in it and this email now is continuosly being recovered. In the meantime my inbox has stopped downloading new messages, even when i press Get New Mail. How can I stop the repeated recovery of the email and how can I get my inbox to download again?

    OK, I persevered and used the Rebuild mailbox option on Mail, actually had to do it twice, but now when I boot up and Mail opens all the previously received iCloud messages I've read on iPhone/iPad are pushed through.
    Back to normal...

  • IMovie has frozen up on me. I've tried rebooting and reinstalling the apps- no help. I can play some of the files- but I can't get into the libraries.Even when I can get something to play the whole system crashes after a few minutes. What can I do?

    I desperately need your help. I was working on iMovie last night when the thing froze up on me. I've tried rebooting. I've tried reinstalling the apps. No change. I can play some of the files- although I can't tell which ones will play until they magically appear. I can't get into the project library or the event library. The bar that lets me scroll through the clips is gone. Even when I can get something to play the whole system crashes after a couple of minutes and generates a "problem report" that says "iMovie Quit Unexpectedly". This all started when I was adding cutaways- and one clip just would not load. After I tried several times everything froze up. Have you ever heard of something like this? Maybe I pushed a button or somehow changed a setting? Maybe some of the video is corrupt? What do you recommend?
    Thanks for any advice you can offer!

    I have tried all the above and nothing seems to work. Any other suggestions?

  • I tried to update my ipod but then it didnt work saying that an unknow error has occured, now itunes is not recognising that an ipod has been plugged in and the picture that comes up when you first get it is on my screen, i dont know what to do?

    i tried to update my ipod but then it didnt work saying that an unknown error has occured, now itunes is not recognising that an ipod has been plugged in and the picture that comes up when you first get it (an arrow leading to the itunes sign) is on my screen, i dont know what to do?

    Error 1604
    This error is often related to USB timing. Try changing USB ports, using a different dock connector to USB cable, and other available USB troubleshooting steps (troubleshooting USB connections. If you are using a dock, bypass it and connect directly to the white Apple USB dock connector cable. If the issue persists on a known-good computer, the device may need service.
    If the issue is not resolved by USB isolation troubleshooting, and another computer is not available, try these steps to resolve the issue:
    Connect the device to iTunes, confirm that the device is in Recovery Mode. If it's not in Recovery Mode,put it into Recovery Mode.
    Restore and wait for the error.
    When prompted, click OK.
    Close and reopen iTunes while the device remains connected.
    The device should now be recognized in Recovery Mode again.
    Try to restore again.
    If the steps above do not resolve the issue, try restoring using a known-good USB cable, computer, and network connection.
    Error 1600, 1601, 1602
    Follow the steps listed above for Error 1604. This error may also be resolved by disabling, deactivating, or uninstalling third-party security, antivirus, and firewall software. See steps in this article for details on troubleshooting security software.

  • My phone seems to delete contacts and info when the battery gets low, is there a solution to this issue?!

    After the most recent update, I've noticed a couple MAJOR changes! 1) The battery life can barely make it through half the day. I have to keep charging it no matter how little I use it. I've even turned off apps running in the background, it didn't make much difference. And 2) When the battery gets really low, at the 10% mark, it deletes contacts and settings. I've lost so many contacts all of the sudden and I constantly have to restore my iPhone. It's so frustrating! And when the battery gets low, it also deletes my e-mail account to receive e-mails on the phone. I'm tired of having to constantly reset my phone carry a charger with me, it's not reliable any longer and I'm not sure why. Help??

    Here is some information on the applecare +:
    http://www.apple.com/support/products/iphone.html
    It appears that you have to buy the applecare within 30 days of buying your phone - you said that your phone warranty is almost over, so when did you buy it??? That could be the explanation for the error.

  • When printing I get notation:"An error has occurred in the script on this page"

    when printing I get notation:"An error has occurred in the script on this page", error 1791-Char 1- error invalid argument-Code 01-Can print Word, but not Web pages. Have Windows 7, Home and Internet Explore 10. Please help

    Sorry that you are having a problem with the script error. 
    Try to clear your CACHE and COOKIES on your internet. 
    Are you able to print from another program, such as Firefox, Google chrome, etc?
    Let me know if it prints. 
    **Click the KUDOS star on the left to say 'Thanks'**
    Please mark a reply "ACCEPTED AS SOLUTION" if it solved your problem, so others can find it.

  • How to install when I keep getting the following massage  on windows 7 64 bit with or with firewall on and vwith or with virus protection on  here is post  This installation package could net be opened verify that the package exist and that you can access

    how to install when I keep getting the following massage  on windows 7 64 bit with or with firewall on and with or with virus protection on  here is post           " This installation package could net be opened verify that the package exist and that you can access"  same when trying to install quicktime

    I'd first try downloading an installer from the Apple website using a different web browser:
    http://www.apple.com/quicktime/download/
    If you use Firefox instead of IE for the download (or vice versa), do you get a working installer?

Maybe you are looking for

  • Calling a class method from another class

    how can i call a method / function of one class without extending that class in another class. and one thing more i want want o check wether any Swing gui is open or closed.

  • IPod Touch 4G frozen on restore

    Hi folks I have an iPod Touch 4G. It is a replacement as my old one failed to work anymore (freezing on restore and had pixel issues anyway). My new one has the most up to date IOS 4.3.5. Today I added my apps back onto it with no issues. When I adde

  • Master Data Extraction from BI to SCM

    Hi..... I am extracting master data from BI InfoObject to SCM InfoObject. The extraction works properly provided master data exists in BI. However, if the InfoObject in BI does not have any master data, the extraction never completes but rather remai

  • Transfer hard drive

    Hi, I have a 15" 2010 MacBook Pro with a 500GB 7200rpm hybrid drive (includes 4GB of SSD). My new 17" 2011 MacBook Pro will be coming in shortly with a 500GB 7200rpm standard HDD. Is there any way to just swap the drives and continue running? I know

  • Duplex printing with Reader XI?

    Adobe Reader XI (11.0.07) does not recognize duplex printing for my Brother HL-5370DW printer.  This occurs in OS X 10.6.8 and Mavericks (on different computers).  All other software, including Acrobat Reader 9 (and earlier versions of Reader) and Ac