Home JPA/Hibernate :sql error 1364 sqlstate hy000 hibernate
Reply: 0

JPA/Hibernate :sql error 1364 sqlstate hy000 hibernate

user3062 Published in May 21, 2018, 10:59 am

I am working on a relationship in spring jpa and facing this issue. I am trying to establish relationship between a subuseraccess table and subuservehicleaccess table.
Now a subuser can have access to multiple vehicles and each vehicle will have a set of access privileges for the sub user.(eg: read,write). The private List<SubUserVehicleAccessFeatureList> property in the first class defines the list of the relation class added later viz SubUserVehicleAccessFeatureList.

I am trying to insert record in these tables and, while I am getting an error sql error 1364 sqlstate hy000 hibernate saying the field subUserAccessFeatureId doesn't have a default value.

I tried to debug and the data while saving is all correct. On the contrary if I remove the @JoinColumn(name = "SUBUSERACCESSFEATUREID")) annotation from the below property private List<SubUserVehicleAccessFeatureList> it works as expected. As a part of convention, we need to have names without underscores and hibernate generates underscored names by default.
Referred this but didn't find a solution.

public class SubUserAccessFeatureList extends TableMetaDataDTO {

/** The sub user access feature id. */
@GeneratedValue(strategy = GenerationType.AUTO)
private Long subUserAccessFeatureId;

/** The sub user id. */
@Column(name = "SUBUSERID")
private Long subUserId;

/** The vehicle id. */
@Column(name = "VEHICLEID")
private Long vehicleId;

/** The vehicle access feature list. */
 @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
 @JoinTable(name = "SUBUSERVEHICLEACCESSFEATURELIST", joinColumns = @JoinColumn(name =
private List<SubUserVehicleAccessFeatureList> vehicleAcccessFeatureList = new ArrayList<SubUserVehicleAccessFeatureList>();

/** The account access feature list. */
@Column(name = "FEATUREID")
@JoinTable(name = "SUBUSERACCOUNTACCESSFEATURELIST", joinColumns = @JoinColumn(name = "SUBUSERID"))
@ElementCollection(fetch = FetchType.LAZY)
private Set<Long> accountAccessFeatureList = new HashSet<Long>();

//Getter setter eliminated

The relation class

public class SubUserVehicleAccessFeatureList {

/** The sub user vehicle feature id. */
@GeneratedValue(strategy = GenerationType.AUTO)
private Long subUserVehicleFeatureId;

/** The vehicle id. */
@Column(name = "VEHICLEID")
private Long vehicleId;

/** The feature id. */
@Column(name = "FEATUREID")
@ElementCollection(fetch = FetchType.LAZY)
private Set<Long> featureId = new HashSet<Long>();
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.305086 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO