Logan Lee

Greenhorn
+ Follow
since Oct 28, 2009
Logan likes ...
Mac Spring Java
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Logan Lee

Did you check the datasource you created on your glassfish application server? Does it exist and is it valid?

how did you configure the JNDI name of your datasource on your application server?
mmmkay it's working now! Apparently a missing beans.xml was the problem.

I didn't put the beans.xml file in the WEB-INF. (or META-INF) directory.
The beans.xml file is empty but it is a required artifact. This file is used to enable CDI services.

No error messages in Jboss console....
Hi Guys,

I'm looking into the new JEE6 features. I'm want to use CDI to display some dynamic list of books on a JSF2 page. But I can't see the list.
The page only displays the static string: "This is a list of the top selling books"

It seems the BookManager is not accessed. What do I need to add?

Thanks.

This is my books.xhtml file:


And a manager bean:
I think that if an exam is going on retirement, no new candidates can register after the retirement date but if you already have a valid voucher, you can probably do the exam even after the retirement date.

Looks like you need to do the exam before 31st of May! (Thanks Mike!)
If you use @EJB or @resource in a ejb those resources are automaticallly made available in the ENC/jndi

Pedro Kowalski wrote:
What is the relation between the ENC and JNDI? Is ENC a JNDI, is it a part of the JNDI or are these two entities unrelated with each other?


The ENC is the component's individual space in the JNDI. It's just a name space in the JNDI.
The ENC is managed by the container.
You can access the resources defined in the ENC via JNDI lookup or via EJBContext methods.

Pedro Kowalski wrote:
Are the ENC parameters read only during deployment and CAN'T be changed at all after the deploy? I just was wandering that if it WOULD be possible to change the ENC value, you might end in an inconsistent EJB state.


EJB have read only access to the ENC/JNDI. You'll get a javax.naming.OperationNotSupported if you try to rebind variables. (this is on the exam)
I think this question goes about the situation where you first perform operations on the entitymanger and then you use run a query (JPQL) that uses this data also in one transaction.

To rephrase: If you for example update an entity using the entitymanager and then you run a query that will display fields from that entity, how can you make sure the query reflects the changes you've done via the entity manager?

--> See the FlushModeType :
http://download.oracle.com/javaee/5/api/javax/persistence/FlushModeType.html

Depends on your working experience with EJB3 and JPA, and also how many hours a day you can spend on it. If you can spend 8 hours a day on studying, then yes you can easily do it within 15 days.

I did the exam today, got 88%.

This is how I prepared for it:

First I read the O'Reilly EJB 3 book during a month after work (maximum 2 hours a day).
Then I did the first mock test of Enthuware's test suite and I got 57%. (failed)
The last 3 days before the exam I studied hard from 8 to 5 using Enthuware test suite and Mikalai Zaikin's guide. This boosted my test scores to > 70%. On the final test I got 81% and as I said on the actual exam 88%. Enthuware is a real help! It's worth the money!!!

List of resources I used:

- O'Reilly Enterprise Javabeans 3.0 book (http://oreilly.com/catalog/9780596009786)
- Enthuware test suite (http://www.enthuware.com/index.php/mockexams/sunjavacertifications/ejb-developer-questions/scbcd-ocpbcd-5-old-exam)
(a great help, contains a lot of exam-like question. This is a must)
- EJB3 spec (http://java.sun.com/products/ejb/docs.html)
- Mikalai Zaikin's guide (http://java.boot.by/scbcd5-guide/) which is a great summary of the specs
- Free sample test: http://java.sun.com/developer/Quizzes/ejb/ejb3.0_simplified_api.html

Good luck!

But what about Application Managed Entity Manager. Can't they also be transaction scoped or extended scoped? Correct me if I'm wrong!



Only container managed contexts can be transaction-scoped, so only Entity Managers that are injected with the @PersistenceContext annotation or it's XML equivalent may be transaction-scoped.
Congratulations.
I'm studying for the exam myself.

What's the amount of questions involving XML deployment descriptor (orm.xml/ejb-jar.xml) you got?

Thanks

Jehan Jaleel wrote:
In other words how can I ensure that Hibernate will only update the one column which changed rather than trying to persist the entire object?


You can use the merge method to synchronize detached entities with your persitence provider. You can only use the persist method on object instances that are the new state.
edit:


save() and persist() result in an SQL INSERT, delete() in an SQL DELETE and update() or merge() in an SQL UPDATE. Changes to persistent instances are detected at flush time and also result in an SQL UPDATE. saveOrUpdate() and replicate() result in either an INSERT or an UPDATE.



Hibernate Session docs
EntityManager API
I am using JBoss5.1.0GA (hibernate) and Oracle XE.
A book can have one or multiple authors (as reflected below)
When I persist a book, it contains a collection of authors. I want the authors also to be persisted (cascade)

I have three tables.

BOOK_TBL
BOOK_ID (PK)
BOOK_AUTHOR_TBL
BOOK_ID (FK)
AUTHOR_ID (FK)
AUTHOR_TBL
AUTHOR_ID (PK)

I have two Entities:
Code snippets:
Book


Author
Nothing special here, except I use a sequence for the PK


When I persist my book, I get:


So it seems it's trying to insert the FK's in the mapping table but can't find the parent key yet.. What am I doing wrong?

Kengkaj Sathianpantarit wrote:
EJB 3 promotes the use of JPA in which JPA Entities are POJOs, therefore displaying 100 objects in View Layer result in zero remote call. Applying "Transfer Object" in this case doesn't help anything but introduce duplicate classes.



Indeed, that also was my opinion.


Kengkaj Sathianpantarit wrote:However in some cases we can create "Value Objects" [DDD, Fowler], which is totally different from "Transfer Objects".



What is the exact difference. When I google it I see references to TO's?
I am trying out EJB3/JPA with the use of design patterns.

In all the examples I've build myself I never used DTO's. I always considered DTO's to be an anti-pattern.
I don't want code duplication. EJB3 Entities are not bound to the container anymore and they can move across my tiers. There is no need create DTO's to carry Entity data.

But now I was having a look at the book 'Beginning Java EE5 from Novice to Professional (Apress 2005)' it has a chapter about Design Patterns and EJB.

It states that you should use DTO's because it's not good practice to allow clients to have remote references
to entities.

  • Calling entity bean methods directly circumvents the business logic contained in session beans, and tends to push the business logic into the UI code.
  • Session beans can protect the UI from changes to the entity beans.
  • Restricting client access to session beans conserves server and network resources.


  • In my view layer (or a client) I would never call a method directly on my entities.
    If I am going to execute BL, I would always go via a session bean. If a user fills in a form, I just re-use the ejb3 entity to populate the fields he just entered and pass that entity to my session layer.

    I don't understand why they are using DTO's. Probably I am missing something here?
    Do you use DTO's in your EJB3 application? Why?

    Thanks in advance.
    Logan