这是一个与使用 JPA 2.0 (Eclipselink 2.4.1) 的继承和双向映射相关的问题。
首先;我不确定这是否是最好的方法,也不确定是否可行。请告诉我您是否认为有更好的方法来做同样的事情,或者几乎同样的事情。
我正在尝试实现一个系统,将用户映射到不同类型的车辆(汽车和卡车)并且所有车辆至少有一张照片。我宁愿只为照片设置一个类(即 VehiclePhoto),因为我不想为所有类型的照片(例如 CarPhoto 和 TruckPhoto)提供服务。
我在上面画了一个类似 UML 图的草图:
各位高手能帮帮我吗?提前感谢=)
我试图按如下方式实现它:
@MappedSuperclass
public abstract class GenericPhoto {
// Abstract class which is common for all kind of photos.
// Can be omitted in this example, but I will include it
// anyway.
protected String description;
//..
}
@Entity
@Table(name="VEHICLEPHOTO")
public class VehiclePhoto extends GenericPhoto {
// This class inherit from GenericPhoto and is a
// photo class for all vehicles (e.g. Car, Truck, ..)
// This class must know its dependency, since bi-directional
// relationship is required.
@Id
@GeneratedValue
private Long id;
@ManyToOne
@JoinColumn(name = "GENERICVEHICLE_ID")
private GenericVehicle genericVehicle;
private boolean coverPhoto;
}
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class GenericVehicle {
// This class is common for all vehicles. For example,
// registration number is common for all vehicles since
// all vehicles needs a registrationnumber.
//
// All vehicles also has one or more VehiclePhoto's which shall
// have a bi-directional relationship to it.
//
// All vehicles also has one User which shall be bi-directional
// relationship.
@Id
@GeneratedValue
protected Long id;
@OneToMany(mappedBy = "genericVehicle", targetEntity = VehiclePhoto.class, cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, orphanRemoval = true)
protected Set<VehiclePhoto> photos;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "USER_ID")
protected User user;
protected String registrationNumber;
//..
}
@Entity
@Table(name = "CARS")
public class Car extends GenericVehicle implements Serializable {
// This class implements a Car and inherit the GenericVehicle
// class, since it has a registrationnumber, one or more photos
// and is owned by a user.
//
// The only specific for the Car class is the yearModel,
// gearbox type, etcetera..
private int yearModel;
//..
}
@Entity
@Table(name = "TRUCKS")
public class Truck extends GenericVehicle implements Serializable {
// Same as the Car description but different fields
}
@Entity
@Table(name = "USERS")
public class User implements Serializable {
// {{ userId
@Id
private String userId;
@OneToMany(mappedBy = "user", cascade = { CascadeType.ALL }, orphanRemoval = false, fetch = FetchType.LAZY)
private Set<Car> cars;
@OneToMany(mappedBy = "user", cascade = { CascadeType.ALL }, orphanRemoval = false, fetch = FetchType.LAZY)
private Set<Truck> trucks;
// ...
}
@Test
public void testCreatePhoto() throws Exception {
User user = new User(TEST_USER_ID, TEST_PASSWORD);
Car car = dg.getTestCar(); // Get a randomized car
Truck truck = dg.getTestTruck(); // Get a randomized truck
VehiclePhoto photoCar = dg.getVehiclePhoto(); // Get a randomized photo for car
VehiclePhoto photoTruck = dg.getVehiclePhoto(); // Get a randomized photo for truck
// Add the relationship between photoCar <-> car, photoTruck <-> truck
photoCar.setGenericVehicle(car);
Set<VehiclePhoto> photoCarsSet = new HashSet<VehiclePhoto>();
photoCarsSet.add(photoCar);
car.setPhotos(photoCarsSet);
photoTruck.setGenericVehicle(truck);
Set<VehiclePhoto> photoTrucksSet = new HashSet<VehiclePhoto>();
photoTrucksSet.add(photoTruck);
truck.setPhotos(photoTrucksSet);
// Add the relationship between user <-> car, user <-> truck
car.setUser(user);
Set<Car> carsSet = new HashSet<Car>();
carsSet.add(car);
user.setCars(carsSet);
truck.setUser(user);
Set<Truck> trucksSet = new HashSet<Truck>();
trucksSet.add(truck);
user.setTrucks(trucksSet);
// Persist the objects
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("vehicle-ejb");
EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
entityManager.persist(user);
entityManager.flush();
}
错误日志:
[EL Finest]: connection: 2013-06-15 20:22:36.509--ServerSession(27042828)--Connection(1579697)--Thread(Thread[main,5,main])--Connection acquired from connection pool [default].
[EL Finer]: transaction: 2013-06-15 20:22:36.509--ClientSession(9988705)--Connection(1579697)--Thread(Thread[main,5,main])--begin transaction
[EL Finest]: query: 2013-06-15 20:22:36.511--ClientSession(9988705)--Thread(Thread[main,5,main])--Execute query DataModifyQuery(name="SEQUENCE" sql="UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + #PREALLOC_SIZE WHERE SEQ_NAME = #SEQ_NAME")
[EL Fine]: sql: 2013-06-15 20:22:36.512--ClientSession(9988705)--Connection(1579697)--Thread(Thread[main,5,main])--UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?
bind => [50, SEQ_GEN]
[EL Finest]: query: 2013-06-15 20:22:36.514--ClientSession(9988705)--Thread(Thread[main,5,main])--Execute query ValueReadQuery(name="SEQUENCE" sql="SELECT SEQ_COUNT FROM SEQUENCE WHERE SEQ_NAME = #SEQ_NAME")
[EL Fine]: sql: 2013-06-15 20:22:36.515--ClientSession(9988705)--Connection(1579697)--Thread(Thread[main,5,main])--SELECT SEQ_COUNT FROM SEQUENCE WHERE SEQ_NAME = ?
bind => [SEQ_GEN]
[EL Finest]: sequencing: 2013-06-15 20:22:36.516--ClientSession(9988705)--Connection(1579697)--Thread(Thread[main,5,main])--local sequencing preallocation for SEQ_GEN: objects: 50 , first: 1, last: 50
[EL Finer]: transaction: 2013-06-15 20:22:36.517--ClientSession(9988705)--Connection(1579697)--Thread(Thread[main,5,main])--commit transaction
[EL Finest]: sequencing: 2013-06-15 20:22:36.584--ServerSession(27042828)--Connection(1579697)--Thread(Thread[main,5,main])--local sequencing preallocation is copied to preallocation after transaction commit
[EL Finest]: connection: 2013-06-15 20:22:36.584--ServerSession(27042828)--Connection(1579697)--Thread(Thread[main,5,main])--Connection released to connection pool [default].
[EL Finest]: sequencing: 2013-06-15 20:22:36.585--UnitOfWork(7351433)--Thread(Thread[main,5,main])--assign sequence to the object (1 -> info.vehicle.domain.Car@cbda60bc)
[EL Finest]: transaction: 2013-06-15 20:22:36.67--UnitOfWork(7351433)--Thread(Thread[main,5,main])--persist() operation called on: info.vehicle.domain.VehiclePhoto@d26de99f.
[EL Finest]: sequencing: 2013-06-15 20:22:36.671--UnitOfWork(7351433)--Thread(Thread[main,5,main])--assign sequence to the object (2 -> info.vehicle.domain.VehiclePhoto@d26de99f)
[EL Finest]: transaction: 2013-06-15 20:22:36.691--UnitOfWork(7351433)--Thread(Thread[main,5,main])--persist() operation called on: info.vehicle.domain.Truck@b295c71e.
[EL Finest]: sequencing: 2013-06-15 20:22:36.691--UnitOfWork(7351433)--Thread(Thread[main,5,main])--assign sequence to the object (3 -> info.vehicle.domain.Truck@b295c71e)
[EL Finest]: transaction: 2013-06-15 20:22:36.719--UnitOfWork(7351433)--Thread(Thread[main,5,main])--persist() operation called on: info.vehicle.domain.VehiclePhoto@b297753e.
[EL Finest]: sequencing: 2013-06-15 20:22:36.72--UnitOfWork(7351433)--Thread(Thread[main,5,main])--assign sequence to the object (4 -> info.vehicle.domain.VehiclePhoto@b297753e)
[EL Finer]: transaction: 2013-06-15 20:22:36.721--UnitOfWork(7351433)--Thread(Thread[main,5,main])--begin unit of work flush
[EL Finest]: query: 2013-06-15 20:22:36.726--UnitOfWork(7351433)--Thread(Thread[main,5,main])--Execute query InsertObjectQuery(User [userId=TEST USER #1])
[EL Finest]: connection: 2013-06-15 20:22:36.728--ServerSession(27042828)--Connection(1579697)--Thread(Thread[main,5,main])--Connection acquired from connection pool [default].
[EL Finer]: transaction: 2013-06-15 20:22:36.729--ClientSession(9988705)--Connection(1579697)--Thread(Thread[main,5,main])--begin transaction
[EL Fine]: sql: 2013-06-15 20:22:36.729--ClientSession(9988705)--Connection(1579697)--Thread(Thread[main,5,main])--INSERT INTO USERS (USERID, PASSWORD) VALUES (?, ?)
bind => [TEST USER #1, PASSWORD]
[EL Finest]: query: 2013-06-15 20:22:36.731--UnitOfWork(7351433)--Thread(Thread[main,5,main])--Execute query InsertObjectQuery(info.vehicle.domain.Car@cbda60bc)
[EL Fine]: sql: 2013-06-15 20:22:36.733--ClientSession(9988705)--Connection(1579697)--Thread(Thread[main,5,main])--INSERT INTO CARS (ID, ACTIVE, BODY, BODYSLANG, COMMERCIALNAME, CREATEDTIME, DESCRIPTION, GEARBOX, KILOMETRES, PRICE, PULLEY, REGISTRATIONNUMBER, VERIFIED, VTRMAKEMODELNAME, YEARMODEL, USER_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
bind => [1, true, _TRUCK_ORDINAL, CAR_STATION_WAGON, sacrifice, 2013-06-15 20:22:36.358, vznxclmndaawethajnahzxgxzzdurifeubrhhqajaiohnjurnrlpcjxfarpbqzqaphgvjjfhzcpozsgfctjnddmhmmncoezhxpqxqdgqgqryysgqsnmryxzlwwqlbkvrksdtrftrgqxnozochtxmznasrhbuxumjzbaqtqujnefvhaeafvcyqcodilpwbnloyzeizcbhekebsdpilfhhrtaxffvnzahnynhnkcwhyvfahrsmywdbcqzsafifwjeielpeyxhbufisfheefybldypnmtpvebnwngmjvjledwpywwbqkvdyjuqzulxdstqukmpctrpxupgpldnobttngdxuvpvjyadoapvszdanspsyoyxefumgbafxdopspbxhocefvsohyutvggoccemreeqdlowwyntgztkbmippjnvqcydkzmwkydgpzdwrxwapgxwnkzeqgmopsfsipqacnkmpvxnkyvsrobppmolfefqbmupgsuwyqefoaiuxjnhxezxnwznyqjjoszmdeuhxomlvoptwmmntjfuegdxvtewosrmpegyjbbdunidfliqyewcicmvbnztuofqovftyljmxixtdoiirrkmxgyycpje, NA, 701421, 904861, PULLEY, the284, false, jebywyypgqorighf, 2009, TEST USER #1]
[EL Finest]: query: 2013-06-15 20:22:36.755--UnitOfWork(7351433)--Thread(Thread[main,5,main])--Execute query InsertObjectQuery(info.vehicle.domain.Truck@b295c71e)
[EL Fine]: sql: 2013-06-15 20:22:36.756--ClientSession(9988705)--Connection(1579697)--Thread(Thread[main,5,main])--INSERT INTO TRUCKS (ID, ACTIVE, BODY, BODYSLANG, COMMERCIALNAME, CREATEDTIME, DESCRIPTION, GEARBOX, KILOMETRES, PRICE, PULLEY, REGISTRATIONNUMBER, VERIFIED, VTRMAKEMODELNAME, YEARMODEL, USER_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
bind => [3, true, _BUS_ORDINAL, BUS_WAGON, axcsjlltvgrgqrvoyldsdykkjop, 2013-06-15 20:22:36.359, qvsiptzlmexveeppkczqcoxcpfmsdwhwamdtwsadohmtgozzxmmvnpwbhpyvzasankutoyfpwjmggsyynehtvhryybltlhdsmqfiueomijkyhewhwnllklkmcwpqnbebbupxmibaeswzgkdkhglmrhaiiehjsivrrjidfoyzvwknaqrdedocopzsluqdvmwgikmkowpobukiwhbgkfypeeetvtzsuiabyxlziqezhrgqlzcqxxhipjsqvtoxukgojhbjubvgbgagonrvbgreqopyrprmdamhssakuxqukevaeuhfopuenednnaambqixriljcwlrqenqcffpirovbzczmxpchcnuhyphtqipcpznhnrzfyofptpcsbesmcssyxaizpfuhxskpiytvpspipdkytulxpxiclqvipjvzpkjrzwqkpzpxtqesclejloawipzrbcagcmhvutkyjwsngenswwc, AUTOMATIC, 190530, 1341699, PULLEY, end208, false, hlklwoixaxg, 1993, TEST USER #1]
[EL Finest]: query: 2013-06-15 20:22:36.762--UnitOfWork(7351433)--Thread(Thread[main,5,main])--Execute query InsertObjectQuery(info.vehicle.domain.VehiclePhoto@d26de99f)
[EL Fine]: sql: 2013-06-15 20:22:36.762--ClientSession(9988705)--Connection(1579697)--Thread(Thread[main,5,main])--INSERT INTO VEHICLEPHOTO (ID, COVERPHOTO, DESCRIPTION, FILE, FILENAME, TITLE, UPLOADTIME, GENERICVEHICLE_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
bind => [2, false, vycazxirmtesotsfohnqnvrtx, [B@142b4dd, this, ckwbcdyalcdcvjmisozfidsxuutqqepbopvntttxadijmfsklysrzlothvlgwmrfkhkhjypbzhlbxoqo, 2013-06-15 20:22:36.359, 1]
[EL Finest]: query: 2013-06-15 20:22:36.765--UnitOfWork(7351433)--Thread(Thread[main,5,main])--Execute query InsertObjectQuery(info.vehicle.domain.VehiclePhoto@b297753e)
[EL Fine]: sql: 2013-06-15 20:22:36.765--ClientSession(9988705)--Connection(1579697)--Thread(Thread[main,5,main])--INSERT INTO VEHICLEPHOTO (ID, COVERPHOTO, DESCRIPTION, FILE, FILENAME, TITLE, UPLOADTIME, GENERICVEHICLE_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
bind => [4, false, stemdxpofqjnkycmwjsvygzawpbuzdbinpyweilqhrrchyenawwkjxhxuuafsrewtbwwshcfiytwccofvzpixqebtjxyeqsakqaa, [B@a49e9a, no, oazjleqshliiicpavrvdpxiqyclzvpkgfpzcrtzteoduxmttzbmfdinetwcwzginhokrxnlbaoqzdnhivrdndoscxvtctfvojhiwbdtyzsbaspvnzgefrurcmdamxyhjwcoyvqweuaacs, 2013-06-15 20:22:36.359, 3]
[EL Fine]: sql: 2013-06-15 20:22:36.768--ClientSession(9988705)--Thread(Thread[main,5,main])--SELECT 1
[EL Warning]: 2013-06-15 20:22:36.769--UnitOfWork(7351433)--Thread(Thread[main,5,main])--Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`vehicle_test`.`VEHICLEPHOTO`, CONSTRAINT `FK_VEHICLEPHOTO_GENERICVEHICLE_ID` FOREIGN KEY (`GENERICVEHICLE_ID`) REFERENCES `CARS` (`ID`))
Error Code: 1452
Call: INSERT INTO VEHICLEPHOTO (ID, COVERPHOTO, DESCRIPTION, FILE, FILENAME, TITLE, UPLOADTIME, GENERICVEHICLE_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
bind => [4, false, stemdxpofqjnkycmwjsvygzawpbuzdbinpyweilqhrrchyenawwkjxhxuuafsrewtbwwshcfiytwccofvzpixqebtjxyeqsakqaa, [B@a49e9a, no, oazjleqshliiicpavrvdpxiqyclzvpkgfpzcrtzteoduxmttzbmfdinetwcwzginhokrxnlbaoqzdnhivrdndoscxvtctfvojhiwbdtyzsbaspvnzgefrurcmdamxyhjwcoyvqweuaacs, 2013-06-15 20:22:36.359, 3]
Query: InsertObjectQuery(info.vehicle.domain.VehiclePhoto@b297753e)
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:324)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:851)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeNoSelect(DatabaseAccessor.java:913)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:594)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:537)
at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:1800)
at org.eclipse.persistence.sessions.server.ClientSession.executeCall(ClientSession.java:286)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:207)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:193)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.insertObject(DatasourceCallQueryMechanism.java:342)
at org.eclipse.persistence.internal.queries.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:162)
at org.eclipse.persistence.internal.queries.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:177)
at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.insertObjectForWrite(DatabaseQueryMechanism.java:471)
at org.eclipse.persistence.queries.InsertObjectQuery.executeCommit(InsertObjectQuery.java:80)
at org.eclipse.persistence.queries.InsertObjectQuery.executeCommitWithChangeSet(InsertObjectQuery.java:90)
at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:286)
at org.eclipse.persistence.queries.WriteObjectQuery.executeDatabaseQuery(WriteObjectQuery.java:58)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:852)
at org.eclipse.persistence.queries.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:751)
at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery.java:108)
at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWork(ObjectLevelModifyQuery.java:85)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2875)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1602)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1584)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1535)
at org.eclipse.persistence.internal.sessions.CommitManager.commitNewObjectsForClassWithChangeSet(CommitManager.java:224)
at org.eclipse.persistence.internal.sessions.CommitManager.commitAllObjectsForClassWithChangeSet(CommitManager.java:191)
at org.eclipse.persistence.internal.sessions.CommitManager.commitAllObjectsWithChangeSet(CommitManager.java:136)
at org.eclipse.persistence.internal.sessions.AbstractSession.writeAllObjectsWithChangeSet(AbstractSession.java:3914)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabase(UnitOfWorkImpl.java:1419)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.commitToDatabase(RepeatableWriteUnitOfWork.java:634)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithPreBuiltChangeSet(UnitOfWorkImpl.java:1565)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.writeChanges(RepeatableWriteUnitOfWork.java:445)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush(EntityManagerImpl.java:798)
at info.vehicle.service.jpa.VehiclePhotoRepositoryTest.testCreatePhoto(VehiclePhotoRepositoryTest.java:94)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.rules.TestWatchman$1.evaluate(TestWatchman.java:48)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:35)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:146)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:97)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103)
at $Proxy0.invoke(Unknown Source)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:145)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:87)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`vehicle_test`.`VEHICLEPHOTO`, CONSTRAINT `FK_VEHICLEPHOTO_GENERICVEHICLE_ID` FOREIGN KEY (`GENERICVEHICLE_ID`) REFERENCES `CARS` (`ID`))
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1041)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4187)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4119)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2815)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2375)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2359)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:842)
... 67 more