File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes Can I use Entity class as my managed bean? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Can I use Entity class as my managed bean?" Watch "Can I use Entity class as my managed bean?" New topic
Author

Can I use Entity class as my managed bean?

Namitha karupaiya
Ranch Hand

Joined: Mar 10, 2004
Posts: 89
If the input fields of the (JSF) form are bound to a managed bean then the user state is automatically synchronized with the bean properties.

Can I use an Entity class as a managed bean? (If this is possible, I don't need to create a separate managed bean & simply persist the Entity instance with the data entered by the user to the database using JPA)
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15964
    
  19

Yes, technically you can, but it's not very flexible. Scan back through this forum over about the last 2 weeks and you'll see that the question has been asked (and answered) before.


Customer surveys are for companies who didn't pay proper attention to begin with.
Namitha karupaiya
Ranch Hand

Joined: Mar 10, 2004
Posts: 89
Please post the links of the relevant threads.
Namitha karupaiya
Ranch Hand

Joined: Mar 10, 2004
Posts: 89
No reply?!
Akaine Harga
Ranch Hand

Joined: Nov 03, 2009
Posts: 79

Can I use an Entity class as a managed bean?

Yes, sure. But this would be a bad practice since you shouldn't fill your ejbs with front-end garbage. And if you don't, the desing pattern will force you to fill you RAM with ejbs saved in session which leads to out-of-mem errors and server crashes. My recommendation would be to leave ejbs as they are and create controller managed bean filled with action methods where you would only instantiate ejbs. If you have trouble accesing Facade methods there just use @EJB annotation when declaring facade objects (ie @EJB MyClassFacadeLocal myClassFL;).


Wanna install linux on a vacuum cleaner. Could anyone tell me which distro sucks better?
willCodeForFood("Java,PHP,C#,XML,VBS,XHTML,CSS,JavaScript,SQL"); //always looking for job opportunities in AU/NZ/US/CA/Europe :P
Namitha karupaiya
Ranch Hand

Joined: Mar 10, 2004
Posts: 89
What I mean by Entity class in not regarding EJB but regarding JPA.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15964
    
  19

JPA is defined as part of the EJB3 specification. The same caveats apply whether you using simple JPA or full EJB.
Namitha karupaiya
Ranch Hand

Joined: Mar 10, 2004
Posts: 89
JPA (JSR 317) is NOT part of EJB (JSR 318) specification starting from JavaEE 6, look at here:

http://java.sun.com/javaee/technologies/index.jsp
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15964
    
  19

Namitha karupaiya wrote:JPA (JSR 317) is NOT part of EJB (JSR 318) specification starting from JavaEE 6, look at here:

http://java.sun.com/javaee/technologies/index.jsp


The operative words are "starting from". On page 441, note the following:


Created document from EJB 3.0 Java Persistence API Final Release draft.


There are no significant differences between JSR-317 and the earlier specs that invalidate the caveats.
Namitha karupaiya
Ranch Hand

Joined: Mar 10, 2004
Posts: 89
Now it is EJB 3.1 not 3.0
Namitha karupaiya
Ranch Hand

Joined: Mar 10, 2004
Posts: 89
No reply?!
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Namitha karupaiya wrote:No reply?!


Why should we? So you can argue more? That will get you no where around here. Have you searched this forum as suggested by Tim? If not, please do so. As he said, this question has been answered multiple times before. And even so, the short answer is you can do it, but it is bad practice and and anti-pattern. So simply, don't do it.


GenRocket - Experts at Building Test Data
Namitha karupaiya
Ranch Hand

Joined: Mar 10, 2004
Posts: 89
Hi Gregg Bolinger,

I searched but could not find. PLEASE post the links of the relevant thread(s), if you are able to find them. (Please treat this as discussion, not argument!)

Thanks.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15964
    
  19

I'm afraid our search engine is no Google[TM].

Most of what I've got here, I found by just paging back over postings for the last month or 2 and looking at likely topic names. I think there may be some others that go into more detail, but they're not immediately recognizable.

http://www.coderanch.com/t/212506/JSF/java/MVC-Model-Domain-Model#1015480

http://www.coderanch.com/t/473818/JSF/java/granularity-JSF-beans#2123780

http://www.coderanch.com/t/469486/JSF/java/JSF-EJB-target-unreachable-returned#2100676

http://www.coderanch.com/t/432929/JSF/java/Represent-Inheritance-Domain-model-JSF#1923469
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

No reply?!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can I use Entity class as my managed bean?
 
Similar Threads
Accessing jsf bean from another jsf bean
Entity Beans must use CMP?
BMT with Entity beans
Is primary key a must for an entity bean
Using EJB and Oracle