Win a 3 month subscription to Marco Behler Videos this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JPA POJO in JSF  RSS feed

 
Chris Ernst
Ranch Hand
Posts: 37
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Folks,

I didn’t know if I am here right so I start to ask my question, otherwise mod please move it to the other thread.

I will try to use the JPA EntityManager. So far so good it still works when I have all in one bean.
What I want is to use DAO’s (see the source code down below).
When I start this project I got an exception called: cannot inject bean eb (its translated from German) but I have no idea what is going wrong.

first my DAO

My EventBean (eb)


When I insert the DAO method into my test method it works
btw. the front end is very smal I only want to show the table

cheers

Chris
Staff note (Tim Holloway):

This isn't really a good candidate for JiG. It's JSF-specific.

 
Tim Holloway
Saloon Keeper
Posts: 18637
70
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't actually worked with JSR-330 injection. I got started before all that, when about the best alternative was the Spring Framework and have been disappointed in that the official standard is not only largely incompatible with that, but also seems to lack some of the abilities that Spring has.

Nonetheless, the basic ideas are the same, so I'll try and fake it.

Actually, I use DAOs as single-table CRUD/Finder components (or occasionally with parent/child sets) and have a separate persistence service layer that allows me to work with complex table interrelationships. The actual Transaction boundary is at the Service layer methods and application code never invokes DAOs directly.

Spring automatically injects the EntityManager into my DAOs. I'm pretty sure that EJB3 has a similar mechanism (haven't looked in a while) and I'm reasonably sure that SPI could do the same. Simplifies things a bit and avoids the need for service lookups that hard-code properties into beans that don't need them.

So in conformance with common practice with EJB-like technologies, I'd have a findAll() method to retrieve the List of TV_tvshows. Spring has a @Transactional annotation, so the logic would be simpler than yours. I'm not 100% certain that a "SELECT" should even need a transaction, although quirks in some environments make me unwilling to flatly say so. A "commit" is supposed to trigger a database update, and SELECT is read-only.

Your JSF Model object (EventBean) isn't a JSF-friendly POJO. The method named "test" cannot be used as a bean property because JSF expects POJO get/set methods Something more like this:


Although for performance and reliability reasons, you'd actually want to cache the find method's results instead of fetching them every time getTvshows() was invoked.

Those are just general design observations, though. I cannot clearly envision what you have connected where so that you get the exception. Try posting the actual stack trace. We can generally make sense of foreign-language error messages.
 
Chris Ernst
Ranch Hand
Posts: 37
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Tim

this was an option and test for me to get the data on another way. So after this I think I will do it like befor, get the data with SQL not JPQL.
There I know what I do and what I have to do :)

thanks anyway

cheers Chris
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!