Hi Krum,
Thank you for such detail explanation on the questions posted so far.
Krum Bakalsky wrote:
( c ) > You can achieve a persistence context that will outlive the JTA transactions by two approaches:
> using EXTENDED persistence context with a stateful session bean;
> using application-managed persistence context (in JavaEE environment you can obtain such a one
through a @PersistenceUnit annotation).
Looks like the @PersistenceUnit annotation is better than EXTENDED persistence context which is only available to stateful session bean.
( d ) > However, BMT is inevitable if you want, for instance, to trigger a transaction from the
> web tier. CMT is only for EJBs. So there are scenarios when the developer to use a BMT
> is the only possible way.
> There is no problem not to start a transaction from the client. But you will have to explain your goals if you want to be advised which approach is more suitable.
What is the purpose of triggering a transaction from web tier/client? Will JTA be supported in BMT in EJB 3.1 or later? My goal is to spread the load of low volume persistence transactions & ad-hoc reporting across multiple Intel hardware. It appears that JTA is sufficient for my requirement, especially for someone who is not familiar with JTA API.
( f ) > The deploy of the app client is complaining that most probably you have messed up the business interface types. Check them once again.
(If your app client lives in a separate JVM, then you must use remote interfaces only)
I have forgotten to mentioned from previous response that I have replaced CustomerRemote with CustomerLocal interface just to demonstrate that app client cannot lookup local interface, since it belonged to a separate container even though the whole Netbeans EAR (EJB & app client) project are in the same JVM, as stated by Java EE 5 & Glassfish FAQ. What is interesting is that it is not necessary to use the Main class in app client (I didn't) but got the same outcomes on Glassfish. ie can reference remote interface but not local one.
It is ashamed that Jave EE 5 doesn't allow implementation of both remote & local interfaces with the same method. Not sure why this was done and whether it will be changed in the future?
> Take a look at this:
http://stackoverflow.com/questions/848675/ejb-annotation-in-clients
I can't quite follow what it is trying to do on a quick glance. It is hard to tell whether the app client was created properly either.
> Are you sure that you have declared correctly your client code as a valid application client ? (maybe this is done through some deployment descriptors, i don't know ) If the container does not recognize it as an app client, then dependency injection is forbidden and you must use look up instead.
There is nothing wrong with the app client generated from a Java EE 5 (EAR) project in Netbeans 6.7 on Windows XP. I have been able to create numerous working projects using this method.
>
http://javahowto.blogspot.com/2009/10/sample-appli...ation-clientxml-java-ee-5.html
I only use EJB 3.0 annotation instead of application-client.xml deployment descriptor.
> Why don't you try to look up the remote interface in the client anyways, instead of having it injected ?
There is no point since I haven't define it.
>
http://forums.netbeans.org/post-47321.html&highlight=
The code looks fine but cannot tell how this project was created but don't believe that it is a Netbeans issue since I am very pleased with 6.7 on Windows though.
( j ) > The only problem will come when a transaction is rolled back, since it will detach your entities:
> If there is a new entity that uses automatic primary key generation, there may be a
> primary key value assigned to the detached entity. If this primary key was generated
> from a database sequence or table, the operation to generate the number may have
> been rolled back with the transaction. This means that the same sequence number
> could be given out again to a different object. Clear the primary key before attempting
> to persist the entity again, and do not rely on the primary key value in the detached
entity.
I am using primary-key class/composite keys as mentioned in ( i ) which does not support automatic primary key generation according to my understanding. This means there would be no chance of the database allocating primary key from recently detached objects in an IDENTITY strategy. Is this correct?
> Something to add about the IDENTITY strategy:
> Another difference, hinted at earlier, between using IDENTITY and other id generation
> strategies is that the identifier will not be accessible until after the insert has occurred. While no
> guarantee is made as to the accessibility of the identifier before the transaction has completed,
> it is at least possible for other types of generation to eagerly allocate the identifier, but when
> using identity, it is the action of inserting that causes the identifier to be generated. It would be
> impossible for the identifier to be available before the entity is inserted into the database, and
> because insertion of entities is most often deferred until commit time, the identifier would not
> be available until after the transaction has been committed.
Not an issue for me. Nevertheless, I am wondering whether you could elaborate the pros & cons of each of these strategies.
Thanks,
Jack