I have been reading spring\'s documentation, but I must say it is a bit confusing, giving several different option on how to configure JPA.
What is the best way, and
I use EclipseLink, but configuration must be very similar. Here you have most important parts.
pom.xml:
org.springframework
spring-orm
${org.springframework-version}
org.eclipse.persistence
eclipselink
2.0.1
javax.persistence
javax.persistence
2.0.0
persistence.xml:
applicationContext-dao.xml:
false
User.java:
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Integer id;
private String name;
// Getters and setters
}
UserDao.java:
@Repository
public class JpaUserDao implements UserDao {
@PersistenceContext
private EntityManager em;
@Override
public Item get(Integer id) {
return em.find(User.class, id);
}
}
UserService.java:
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserDao userDao;
@Transactional
@Override
public User getUser(Integer id) {
return userDao.get(id);
}
}
Hope it helps.