user8713731
user8713731

Reputation:

Setting fields in the database using setters in Spring

I have two entities mapped with @OneToOne relationships. So, User has a foreignKey field to Transaction. If I want to set a field in the transaction, can I do it using UserRepository?

User user=userRepository.findOne(long id ) // find the user with that id

user.getTransactions().setNumber(6); ? //getTransactions is the field that is mapped to Transactions

Number is a field in transactions. Or is there another way?

Upvotes: 1

Views: 85

Answers (1)

Atimene Nazim
Atimene Nazim

Reputation: 419

If I understend what do you want. You want to use userRepository to update Transactions object. I think that's possible but you have to use Cascade mode.

You can find here more informations about it :

https://vladmihalcea.com/a-beginners-guide-to-jpa-and-hibernate-cascade-types/

Upvotes: 3

Related Questions