Community Bot 1 1 1 silver badge. Bozho Bozho k gold badges silver badges bronze badges. Did you declare the transaction manager? Kartoch Kartoch 7, 9 9 gold badges 37 37 silver badges 66 66 bronze badges.
Which transaction manager did you declare? Knowing that might give a hint. Any error messages or exceptions? If you step through the code in a debugger, what do you see happening? I'm using org. JpaTransactionManager — Albinoswordfish. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Does ES6 make JavaScript frameworks obsolete? Podcast Do polyglots have an edge when it comes to mastering programming Featured on Meta.
Now live: A fully responsive profile. Visit chat. Autowired; import org. Service; import org. Transactional; import com. PersonDao; import com. Spring configuration Create Configuration class under com. Bean; import org. ComponentScan; import org. ComponentScans; import org. Configuration; import org. JpaTransactionManager; import org. LocalEntityManagerFactoryBean; import org. Run application Create a main class to test the above spring-hibernate-jpa configuration. AnnotationConfigApplicationContext; import com.
AppConfig; import com. Person; import com. Download Sources. Hibernate 5 and JPA 2 - Persist, find, merge and remove example. As you can see, not all fields need annotation.
JAP will use the default value for example, use the column name in the data table to exactly match the attribute name , so in many cases, you do not need to specify the metadata explicitly. It should be noted that in the Entree class, I did not add annotation to the String property "name" or the boolean property "vegetarian". Of course, the most important thing in the ORM mechanism is to specify the correspondence between Objects and databases.
Because the instances of other classes are also managed by EntityManager, you can specify "cascade" rules. For example, when a Restaurant is deleted, all associated Addresses will also be deleted at the same time. Below, you will see test cases for this scenario. This metadata is used to describe how the primary key is generated in the database.
The best way for Data Access Layer is to establish a common interface to hide all the implementation details of the persistence layer. Switching to other implementations will not affect the system architecture. At the same time, this also provides convenience for the business logic layer, making it easier to implement stub or mock testing. RestaurantDao is an interface. Note that it does not depend on any JPA or Spring classes.
In fact, it only depends on its own domain model in this simple example, there is only one, that is Restaurant :. For the implementation of the interface, I used Spring's JpaDaoSupport class, which provides a convenient method to obtain JpaTemplate.
JpaTemplate is also optional. If you don't want Spring's automatic processing of JPA exception transactions, you can completely avoid using JpaTemplate.
0コメント