Reputation: 1759
I have an Entity with several fields:
@Entity
public class Leilighet {
@Id @GeneratedValue(strategy = GenerationType.AUTO)
private Long leilighetId;
private String navn;
private String beskrivelse;
private String adresse;
private String postNr;
private String postSted;
private double pris;
//The following fields should not be stored:
private String filename;
private String filetype;
private String filesize;
private byte[] filebin;
....
}
I have a corresponding form and Action that will populate this object and persist it to mySql. This is all good when it comes to storing new "Leilighet"-entities.
But when im using this form to "edit" an existing "Leilighet", I have stumbled upon something i cant figure out what to do.
For editing purposes i do not want to load the entire uploaded file. It is enough to just show the filename to indicate that there is a file present. If the user chooses a new File then it should be overwritten, but if the user chooses nothing then the present file should be kept.
But I cant figure out how to make hibernate do what i want. Unless i populate the filebin
with the actual file, hibernate will just delete the file.
How can I tell hibernate to just update the other fields and not the filefields?
Upvotes: 0
Views: 376
Reputation: 691715
Hibernate supports loading individual properties lazily. See http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#performance-fetching-lazyproperties for details.
Or you could just use a DTO with only the fields you want in this specific use-case, and execute a query with the appropriate projections in order to populate this DTO from the database.
Upvotes: 1