Reputation: 1012
In my Spring-MVC (along with Hibernate) project, I have a table called 'Division' containing all divisions in the institute. It is referenced in other table called 'Assignment'. Here is what I want to achieve? 1. Fetch division data always from database using Hibernate. But never update division data while saving 'Assignments' or any other entity.
I am not using any cache. @Immutable reads data only once from database, but, I want to fetch 'Division' data from database every time I access it.
Upvotes: 0
Views: 416
Reputation: 3475
You should use something like this:
@ManyToOne
@JoinColumn(name = "column_name", referencedColumnName = "reference",
insertable = false, updatable = false)
private aaa bbb;
Notice the insertable and updatable parameters.
Upvotes: 2
Reputation: 2027
If I understood right you have something like:
@Entity
public class Division {
...
@OneToMany
Set<Assignment> getAssignments(){}
...
}
@Entity
public class Assignment{
...
@ManyToOne
Division getDivision(){}
...
}
If that is the case; then you just need a FetchType.EAGER:
@Entity
public class Assignment{
...
@ManyToOne(fetch = FetchType.EAGER)
Division getDivision(){}
...
}
Upvotes: 1