Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Help coderanch get a
new server
by contributing to the
fundraiser
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Ron McLeod
Paul Clapham
Devaka Cooray
Liutauras Vilda
Sheriffs:
Jeanne Boyarsky
paul wheaton
Henry Wong
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Tim Moores
Carey Brown
Mikalai Zaikin
Bartenders:
Lou Hamers
Piet Souris
Frits Walraven
Forum:
Java in General
Not Updating the child entity Hibernate
Mason Wyatt
Greenhorn
Posts: 23
posted 4 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I have an issue occur in my work project, the problem is Hibernate won't update my child entity when I update it from the View.
my code parent class is:
@OneToMany(cascade = CascadeType.ALL, mappedBy = "permitType", fetch = FetchType.EAGER) private Set<BlockDate> blockDates; ..... public Set<BlockDate> getBlockDates() {return blockDates;} public void setBlockDates(Set<BlockDate> blockDates) {this.blockDates = blockDates;}
My child class is :
@Entity @Table(name="block_date") public class BlockDate implements GenericModel<Long> { @Id @GeneratedValue(strategy = GenerationType.TABLE, generator = "block_date") @TableGenerator(name = "block_date", allocationSize = 30, initialValue = 10000) private Long id; @Column(name = "effective_date", nullable = false) private DateTime effectiveDate; @ManyToOne @JoinColumn(name = "permit_type_fk") private PermitType permitType; @Override public Long getId() {return id;} public void setId(Long id) {this.id = id;} @JsonSerialize(using = CustomDateTimeSerializer.class) public DateTime getEffectiveDate() {return effectiveDate;} public void setEffectiveDate(DateTime effectiveDate) {this.effectiveDate = effectiveDate;} public PermitType getPermitType() {return permitType;} public void setPermitType(PermitType permitType) {this.permitType = permitType;} }
My controller is
if (getBlockDates() != null ) { Set<BlockDate> blockDates = new HashSet<>(); DateTime effectiveDate; DateTimeZone timeZone = DateTimeZone.forID(permitType.getPermitArea().getOrganisation().getTimezone()); for (String blockDateString : getBlockDates()){ effectiveDate = DATEPICKER_FORMATTER.parseDateTime(blockDateString).withZone(timeZone).withTimeAtStartOfDay(); blockDates.add(getBlockDateAtt(permitType, effectiveDate)); System.out.println("test dates " + blockDateString); //this is testing how many entry from user } permitType.setBlockDates(blockDates); System.out.println("test the new child entity " + permitType.getBlockDates().size()); //it sets the new record on child entity if i print to consol but it wont applies on the DB } else{ permitType.setBlockDates(new HashSet<>()); System.out.println("test null " + permitType.getBlockDates().size()); // this show 0 but in the DB wont updated the child, it still have the old record }
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Multiple representations of the same entity are are being merged
DatetimePicker problem in struts2
Requests not selecting Entity from the eHcache hitting the DB instead
Castor and java.util.Calendar
HTML:CHECKBOX
More...