spring-data-jdbc

Nested data structure with Spring Data JDBC

北战南征 提交于 2019-12-23 12:16:32
问题 I wanted to create a nested datastructure. Entity1 contains Objects of type Entity2 stored in a Map. Entity2 should contain a Map of Objects of Entity3 . The first part, Entity1 and Entity works fine. When I add Entity3 , an Exception occurs. When I executed a simple test the following Exception occured: java.lang.IllegalArgumentException: Target bean of type org.springframework.data.util.Pair is not of type of the persistent entity (org.hameister.filmwatcher.nested.Entity2)!:org

How to insert a record with custom id use Spring data jdbc?

徘徊边缘 提交于 2019-12-23 10:18:04
问题 For Spring Data JPA, I can use annotation @GeneratedValue(strategy = GenerationType.AUTO) insert a record with custom id, but for Spring Data JDBC, how to insert a record with custom id? I had tried to insert with id, but no any exception threw, and the record is not inserted into the table. 回答1: The way to do that with Spring Data JDBC is to register a BeforeSaveEvent ApplicationListener that creates the id and sets it in the entity. @Bean public ApplicationListener<BeforeSaveEvent>

Why does Spring-data-jdbc not save my Car object?

一笑奈何 提交于 2019-12-21 09:36:33
问题 I'm playing around with spring-data-jdbc and discovered a problem, with I can't solve using Google. No matter what I try to do, I just can't push a trivial object into the database (Bean1.java:25): carRepository.save(new Car(2L, "BMW", "5")); Both, without one and with a TransactionManager + @Transactional the database (apparently) does not commit the record. The code is based on a Postgres database, but you might also simply use a H2 below and get the same result. Here is the (minimalistic)

How to tweak NamingStrategy for Spring Data JDBC

不问归期 提交于 2019-12-10 18:44:20
问题 how do i tweak the Spring Data JDBC NamingStrategy to behave like Hibernate´s PhysicalNamingStrategy ? I have the following entity: /** * Campus domain model class. * Handles information about campus. * * @author thomas.lang@th-deg.de */ @Data @AllArgsConstructor(access = AccessLevel.PRIVATE, onConstructor = @__(@PersistenceConstructor)) public class Campus { private final @Id @Wither long campusId; @NotNull @Size(min = 3) private String campusName; /** * Creates a new campus. * * @param

Why does Spring-data-jdbc not save my Car object?

折月煮酒 提交于 2019-12-04 04:16:10
I'm playing around with spring-data-jdbc and discovered a problem, with I can't solve using Google. No matter what I try to do, I just can't push a trivial object into the database (Bean1.java:25): carRepository.save(new Car(2L, "BMW", "5")); Both, without one and with a TransactionManager + @Transactional the database (apparently) does not commit the record. The code is based on a Postgres database, but you might also simply use a H2 below and get the same result. Here is the (minimalistic) source code: https://github.com/bitmagier/spring-data-jdbc-sandbox/tree/stackoverflow-question Can

Spring Data JDBC: DataRetrievalFailureException : Unable to cast [oracle.sql.ROWID] to [java.lang.Number]

六眼飞鱼酱① 提交于 2019-12-02 08:56:41
问题 I am new to Spring Data JDBC, and I am struggling to create a simple Dto and get it persisted on the DB. I am using Spring-Boot 2.1.1.RELEASE and and Oracle 12 Database. UserDto @Table(value="USERS_T") public class UserDto extends PersistableDto { @Id @Column(value="USR_USERNAME") private String userName; @Column(value="USR_FIRSTNAME") private String firstName; @Column(value="USR_LASTNAME") private String lastName; ..... } UserDao @Repository public interface UserDao extends CrudRepository

Spring Data JDBC / Spring Data JPA vs Hibernate

让人想犯罪 __ 提交于 2019-11-28 19:21:09
问题 What are the typical real life scenarios where one would choose Spring Data JDBC / Spring Data JPA vs Hibernate? I would like to understand the scenarios where either of these implementations are best suited. 回答1: As @Naros said, the question as it is currently in the title doesn't really work. It seems we should really look at 4 options and mostly list the pros of each approach, the cons are the absence of the pros of the other: JDBC without Spring Data You get 100% fine-grained control over