spring-data-r2dbc icon indicating copy to clipboard operation
spring-data-r2dbc copied to clipboard

Add support for composite Id's

Open angstream555 opened this issue 6 years ago • 13 comments

No way to specify composite id for usage ReactiveCrudRepository

angstream555 avatar Aug 01 '19 13:08 angstream555

We depend on upstream feature availability in Spring Data Relational for composite Id's, see DATAJDBC-352.

mp911de avatar Aug 01 '19 13:08 mp911de

any idea when it will be done?

peterjurkovic avatar Dec 20 '19 09:12 peterjurkovic

No, we don’t have this feature scheduled yet as we’re busy with other tasks. A pre-requisite is the composite I’d support in Spring Data Relational as the R2DBC module depends on a shared library.

mp911de avatar Dec 20 '19 12:12 mp911de

Can you suggest any workaround for this until it's done?

edit: I just skipped these annotations, used one element of the composite primary key as a "key" for Repository and used custom query with @Query annotation. Nevertheless, it would be nice to have that feature to make Repository definition right without workarounds.

edit 2: I handled composite key with Tuple2 object. This is kind of workaround, which allows me to reflect schema of the table with composite primary key in the java repository interface and entity class.

pwittchen avatar Apr 07 '21 21:04 pwittchen

@pwittchen do you mind to explain how did you did it with Tuple2?

porfirioribeiro avatar Apr 23 '21 16:04 porfirioribeiro

@porfirioribeiro

Something like this:

@Repository
public interface UserRepository extends R2dbcRepository<User, Tuple2<BigDecimal, String> {
  //...
}

I know, this is kind of workaround and won't work with Repository methods provided out of the box like findById(Id) etc. and you need to write custom methods with custom queries anyway, but I keep it for code documentation purposes to avoid providing any (non-composite) key, which is not real database key just to satisfy interface signature and introduce inconsistency between java code in the repository and database schema.

pwittchen avatar Apr 23 '21 16:04 pwittchen

this is still forgotten =/

RodRich1991 avatar Mar 22 '22 21:03 RodRich1991

@pwittchen Can you please give a reference to your code?

palaknagda avatar Apr 07 '22 14:04 palaknagda

@palaknagda Code related to my comment is proprietary and is not open-source. You can see a general idea in my code snippet in the earlier comment. Nevertheless, it does not solve this problem and query inside @Query annotation should work regardless of this change.

pwittchen avatar Apr 07 '22 14:04 pwittchen

Any updates???

tiagorg-cit avatar Apr 27 '22 20:04 tiagorg-cit

Still depends on spring-projects/spring-data-relational#574. A well-crafted pull request along with a decent design can always speed things up.

mp911de avatar Apr 28 '22 07:04 mp911de

More than 3 years later, no updates so far?

paulushcgcj avatar Mar 06 '23 21:03 paulushcgcj