NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Best practises for building on JSF CRUD

 
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users
View previous topic :: View next topic  
Author Message
setecastronomy



Joined: 11 Jul 2011
Posts: 4

PostPosted: Fri Jul 15, 2011 9:55 am    Post subject: Best practises for building on JSF CRUD Reply with quote

I'm quite new to jpa and jsf.
I liked very much the netbeans wizards which create entity bean from database and JSF pages, controllers and ejb facades.
That is a good starting point but obviously in a real project you have to customize its behavior writing your own code. I wonder which is the best way to build incrementally on what netbeans wizards did for me.
What if some database tables have to be changed slightly ?
What if you need to work with two databases at the same time ?
I can make another example.
The code for listing all objects of type 'Products' is automatically generated and it is good and clean.
I need a filtered list of 'Products' in some other pages in order to display, for example, what a customer bought or for letting him select what he wants.
It is not difficult to create and execute the queries for filtering the products, but it is not so easy for me to elegantly merge them with the wizard-created paginator; I suppose it can be done applying some sort of strategy pattern, but the jpa code is inside an injected ejb facade...
Any advice ?
Referring to the example, instead of duplicating the jsf code for the product list I used templating and composition from facelets. Don't know if it would be better to use a custom component passing what varies with parameters...

Thanks for any suggestion
Filippo
Back to top
setecastronomy



Joined: 11 Jul 2011
Posts: 4

PostPosted: Fri Jul 22, 2011 9:12 am    Post subject: Reply with quote

Really no suggestions on this subject ?
I'm quite new to JSF and JPA, so I cannot understand if the netbeans wizards for Entity and JSF are only a proof of concept or real tools for developing applications. I suppose the generated code follows the best practices and the applicable design patterns, so I should build on it preserving its architecture. I would need some help in figuring out how to do that. My major concerns are the following:
- which is the best way to filter the objects according to different criteria at the database side ? Do I add methods in the stateless ejb or do I use some strategy pattern ?
- netbeans generated code uses jta inside stateless ejb. What if I need to persist or merge different objects in the same transaction ? Do I have to put a method for each possible combination of objects inside the ejb or there is something better ?
- if I use lazy fetch of collections I can postpone database queries to the moment I really need those data. What if I'm only interested to the objects which meet some additional criteria ? Is there a way to filter them at the DB side ? From what I found in internet it seems jpa has nothing for it, but some implementations have their proprietary way of doing that... Any suggestions ?

By the way I have another curiosity to satisfy...
When I persist an object which has an auto-increment ID at the database side how does jpa retrieve that ID ? I mean that ID is generated by the DB and it is not known by jpa during the insert, so I cannot figure out what jpa does behind the scenes to know that ID. I wonder if it is magic ??

May be this is not the right place for my questions. In that case forgive me and please point me to a forum where I can find the answers I'm looking for.

Many thanks
Filippo
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo