Do I need elements in persistence.xml?

The persistence.xml has a jar-file that you can use. From the Java EE 5 tutorial: <persistence> <persistence-unit name=”OrderManagement”> <description>This unit manages orders and customers. It does not rely on any vendor-specific features and can therefore be deployed to any persistence provider. </description> <jta-data-source>jdbc/MyOrderDB</jta-data-source> <jar-file>MyOrderApp.jar</jar-file> <class>com.widgets.Order</class> <class>com.widgets.Customer</class> </persistence-unit> </persistence> This file defines a persistence unit named … Read more

Hibernate Annotations – Which is better, field or property access?

There are arguments for both, but most of them stem from certain user requirements “what if you need to add logic for”, or “xxxx breaks encapsulation”. However, nobody has really commented on the theory, and given a properly reasoned argument. What is Hibernate/JPA actually doing when it persists an object – well, it is persisting … Read more

Spring: @Component versus @Bean

@Component Preferable for component scanning and automatic wiring. When should you use @Bean? Sometimes automatic configuration is not an option. When? Let’s imagine that you want to wire components from 3rd-party libraries (you don’t have the source code so you can’t annotate its classes with @Component), so automatic configuration is not possible. The @Bean annotation … Read more

Does Spring @Transactional attribute work on a private method?

The answer your question is no – @Transactional will have no effect if used to annotate private methods. The proxy generator will ignore them. This is documented in Spring Manual chapter 10.5.6: Method visibility and @Transactional When using proxies, you should apply the @Transactional annotation only to methods with public visibility. If you do annotate … Read more

Difference between and

<context:annotation-config> is used to activate annotations in beans already registered in the application context (no matter if they were defined with XML or by package scanning). <context:component-scan> can also do what <context:annotation-config> does but <context:component-scan> also scans packages to find and register beans within the application context. I’ll use some examples to show the differences/similarities. … Read more