Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
I am new to JPA and need some help understanding persisting JPA parent entity along with it's child (through Mapping).
Say I have following two entities
Now I am trying to save Employee setting Address Entity to it.But it throws a foreign key validation exception because e_id is auto_increment and is generated by database while save.
Does JPA provide some mechanism to handle this ?
Since your Employee entity doesn't have a compound primary key, you don't need to set all those parameters on Address just to target your employee. Try something like this:
Some highlights you should consider when refactoring your code:
* insertable and updatable , when setted to false, are meant to inform the persistence provider that whenever an insert and/or update operation are fired on Address entity it should not include the mapping on the generated query.
* referencedColumnName is used to specify a column name which the foreign key targets. When not present, the default behavior is target's primary key.
Just remember, the Entity who holds the "mappedBy" is the target(Address), the other one the source Entity(Employee).
Could you hold this puppy for a sec? I need to adjust this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth