Spring Boot: "Column 'username' cannot be null" on #manytoone join column - java

I'm trying to post the following json file into mysql database in postman.
{
"rem_month": 3,
"rem_day": 23,
"description": "Happy birthday!",
"username": "mortykrox93"
}
But i keep getting the error "Column 'username' cannot be null"
The app is supposed to allow me to login and add multiple reminders for each user.
Here is the sql files the entities are supposed to model:
user.sql
USE `login-reminder`;
CREATE TABLE `user` (
`email_id` varchar(30) DEFAULT NULL,
`password` varchar(30) DEFAULT NULL,
`username` varchar(30) NOT NULL,
PRIMARY KEY(`username`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
reminder.sql
USE `login-reminder`;
CREATE TABLE `reminder` (
`rem_num` int(12) NOT NULL,
`rem_month` int(2) DEFAULT NULL,
`rem_day` int(2) DEFAULT NULL,
`description` varchar(255) DEFAULT NULL,
`username` varchar(30) NOT NULL,
PRIMARY KEY(`rem_num`),
FOREIGN KEY(`username`) REFERENCES user(`username`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
Here are the two entity files:
User.java
#Entity
#Table(name="user")
public class User {
#Column(name="email_id")
private String emailId;
#Column(name="password")
private String password;
#Id
#Column(name="username")
private String username;
#OneToMany(mappedBy="theUser", cascade = CascadeType.ALL)
private List<Reminder> reminders;
public User() {
}
public User(String emailId, String password, String username) {
this.emailId = emailId;
this.password = password;
this.username = username;
}
public String getEmailId() {
return emailId;
}
public void setEmailId(String emailId) {
this.emailId = emailId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
Reminder.java
#Entity
#Table(name="reminder")
public class Reminder {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name="rem_num")
private int remNum;
#Column(name="rem_month")
private int remMonth;
#Column(name="rem_day")
private int remDay;
#Column(name="description")
private String description;
#ManyToOne
#JoinColumn(name="username")
private User theUser;
public Reminder() {
}
public Reminder(int remNum, int remMonth, int remDay, String description) {
this.remMonth = remMonth;
this.remDay = remDay;
this.description = description;
}
public int getRemNum() {
return remNum;
}
public void setRemNum(int remNum) {
this.remNum = remNum;
}
public int getRemMonth() {
return remMonth;
}
public void setRemMonth(int remMonth) {
this.remMonth = remMonth;
}
public int getRemDay() {
return remDay;
}
public void setRemDay(int remDay) {
this.remDay = remDay;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
Here is the restcontroller.
ReminderController.java
#RestController
public class ReminderController {
#Autowired
private ReminderRepository reminderRepository;
#GetMapping("/reminders")
public List<Reminder> getAllReminders() {
return reminderRepository.findAll();
}
#PostMapping("/reminders")
#CrossOrigin(origins = "http://localhost:4200")
public Reminder createReminder(#RequestBody Reminder reminder) {
return reminderRepository.save(reminder);
}
}
If anyone can help I would appreciate it. Not sure if my entities are matching up with my sql statements, any suggestions would help.

Check your reminder sql, it's username field is set as not null.
The binding is with the User object. So, in your json, it you should send the user like this:
{
"rem_month": 3,
"rem_day": 23,
"description": "Happy birthday!",
"theUser":{
"username":"mortykrox93",
//and other fields if necessary
}
}

This is occurring because of there is no field named username present in Reminder entity class and you are referring to same class in controller with annotation #requestbody to be bind with the request. Actually during deserialization no valid mapping is present for json field named username. so by default username is being set as null because of its datatype string.
Note: It's better to use separate model/pojo class for binding the request. And then map it to proper entity objects.

First, you need change your json that indicates by #user404:
{
"rem_month": 3,
"rem_day": 23,
"description": "Happy birthday!",
"theUser":
{
"username":"mortykrox93",
//and other fields if necessary
}
}
also, the problem is in jackson deserialize, you need to use the anotation for make the relashionship in jackson (is different that Hibernate/JPA) #JsonBackReference and #JsonManagedReference:
In User entity:
#JsonBackReference
#OneToMany(mappedBy="theUser", cascade = CascadeType.ALL)
private List<Reminder> reminders;
In Reminder Entity:
#JsonManagedReference
#ManyToOne
#JoinColumn(name="username")
private User theUser;
Anyway, is recomended use separated DTO classes for transfer data and add in those the jackson annotation. In the entity only use JPA annotations.

Related

SpringBoot + PostgreSQL "Column does not exist"

I have been trying to retrieve all data from the table but getting
"Caused by: org.postgresql.util.PSQLException: ERROR: column tenantenti0_.module_name does not exist"
I have tried all the below still the issue persists:
Adding in application.properties file --> spring.jpa.properties.hibernate.default_schema=${your-default-schema-name}
No camel case issue either in table column name or at code side.
Have mentioned the schema name as well under #Table(name = "tenant_info", schema = "public"), however for me it's public so shouldn't effect only in case of custom schema it needs to be mentioned.
Have tried using #namedQuery in entity class and #query in repository class still the same issue.
Below is my Entity class:
#Entity
#Table(name = "tenant_info", schema = "public")
#NamedQuery(name = "TenantEntity.findAll", query = "SELECT t FROM TenantEntity t")
#ApplicationScope
public class TenantEntity implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#Column(name = "id")
private int id;
#Column(name = "tenant_id")
private String tenantId;
#Column(name = "module_name")
private String moduleName;
#Column(name = "url")
private String url;
#Column(name = "username")
private String userName;
#Column(name = "password")
private String password;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTenantId() {
return tenantId;
}
public void setTenantId(String tenantId) {
this.tenantId = tenantId;
}
public String getModuleName() {
return moduleName;
}
public void setModuleName(String moduleName) {
this.moduleName = moduleName;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
Below is my Repository class:#Repository
public interface TenantRepository extends JpaRepository<TenantEntity, String> {
public List<TenantEntity> findAll();
public TenantEntity findByTenantId(String tenantId);
public List<TenantEntity> findByModuleName(String moduleName);
}
Have attached the table pic.
CREATE TABLE IF NOT EXISTS public.tenant_info (
id integer NOT NULL,
tenant_id text COLLATE pg_catalog."default" NOT NULL,
module_name text COLLATE pg_catalog."default" NOT NULL,
url text COLLATE pg_catalog."default" NOT NULL,
username text COLLATE pg_catalog."default" NOT NULL,
password text COLLATE pg_catalog."default" NOT NULL,
CONSTRAINT tenant_info_pkey PRIMARY KEY (id)
) TABLESPACE pg_default;
I think that there could be two problems you are facing and I cannot comment so I have to answer just to try to help(Sorry if not useful). I believe that it may not be the schema but I would need you to upload your sql for the table to see it. It seems that it may be column not the table but the problem may be with
#Column(name = "module_name")
private String moduleName;
If you look at your sql if you have quotes in postgres you may have to escape them in your java code for it to work properly. Which would make it
#Column(name = "\"module_name\"")
private String moduleName;
Once again sorry if it isn't helpful But can't comment yet so really hopeful that this will help. When I had schema naming issue it wouldn't even say column doesn't exist but the table as a whole would be missing.
This can be caused because your database schema is not in synced with your Entity class. My advice is to inspect your database schema to see if your table has all the columns you expected. Might be more helpful if you show us your database table ;)

error while setting authorities with Spring security

I use spring security and have some problems when starting the authentication process
Here is my class USER
#Entity
#Table(name="MEMBRE")
public class Membre implements UserDetails, Serializable {
...................
private ArrayList<Role> authorities;
#ManyToMany
#JoinTable(
name="MEMBRE_ROLE",
joinColumns={#JoinColumn(name="id_membre", referencedColumnName="id_membre")},
inverseJoinColumns={#JoinColumn(name="id_role", referencedColumnName="id_role")})
public Collection<Role> getAuthorities() {
return this.authorities;
}
public void setAuthorities(ArrayList<Role> authorities) {
this.authorities = authorities;
}
................
}
Here is my class Role (GrantedAuthority)
#Entity
#Table(name="ROLE")
public class Role implements GrantedAuthority, Serializable {
/**
*
*/
private static final long serialVersionUID = 4160725609927520747L;
private Integer id;
private String role;
#Transient
public String getAuthority() {
return this.role;
}
#Id
#GeneratedValue
#Column(name = "id_role", unique = true, nullable = false, precision = 9, scale = 0)
public Integer getId() {
return this.id;
}
#Column(name = "role", nullable = false, length = 20)
public String getRole() {
return this.role;
}
public void setId(Integer id) {
this.id = id;
}
public void setRole(String role) {
this.role = role;
}
}
Here is my table MEMBRE_ROLE
CREATE TABLE IF NOT EXISTS `MEMBRE_ROLE` (
`id_role` INT NOT NULL AUTO_INCREMENT ,
`id_membre` INT NOT NULL),
PRIMARY KEY (`id_role`, `id_membre`) ,
CONSTRAINT `fk_membre_role_membre`
FOREIGN KEY (`id_membre` )
REFERENCES `membre` (`id_membre` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_membre_role_role`
FOREIGN KEY (`id_role` )
REFERENCES `role` (`id_role` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
And when I try to authenticate, I get the following error
org.springframework.security.authentication.InternalAuthenticationServiceException: IllegalArgumentException occurred while calling setter for property [domain.Membre.authorities (expected type = java.util.ArrayList)]; target = [domain.Membre#1807f3f2], property value = [[domain.Role#16cc0706, domain.Role#88b48]] setter of domain.Membre.authorities; nested exception is IllegalArgumentException occurred while calling setter for property [domain.Membre.authorities (expected type = java.util.ArrayList)]; target = [domain.Membre#1807f3f2], property value = [[domain.Role#16cc0706, domain.Role#88b48]]
I understand that the setter isn't properly defined, but I can' see how to manage it and if the mapping of authorities is properly defined considering spring security
To not confuse JPA, use the same type for field, getter and setter:
private Collection<Role> authorities;
public Collection<Role> getAuthorities() {
return this.authorities;
}
public void setAuthorities(Collection<Role> authorities) {
this.authorities = authorities;
}
(JPA annotations omitted for brevity.)
I tried to debug repacing my setter method by
public void setAuthorities(Object authorities) {
this.authorities = (ArrayList<Role>)authorities;
}
And I get a PersistentBag as argument for authorities
Here is the inspection of authorities expression
Authorities
bag --> ArrayList
elementData --> Object[10]
[0] --> Role
1 --> Role
How to get an ArrayList as argument ? I suppose there is an issue with the mapping.
I found this post on internet, but it didn't give me a solution that works
http://www.coderanch.com/t/431759/ORM/databases/JPA-returning-collection-type-PersistentBag
finally I found a temporary solution, not very elegant, but it works. If you have a better solution ..........
public void setAuthorities(PersistentBag authorities) {
final List<Object> listObject = Arrays.asList(authorities.toArray());
final ArrayList<Role> roles = new ArrayList<Role>();
for (final Object object : listObject) {
if (object instanceof Role) {
roles.add((Role)object);
}
}
this.authorities = roles;
}

Property nulled in the response from Spring/Hibernate

I have a Javascript application that uses Java as a backend with Hibernate, Spring and MySQL DB . When reading data everything works fine and as expected but when trying to edit it on the client side I can see strange behaviour. Even though my server request looks like this :
{"data":{"Draggable":true,"Resizable":true,"StartDate":"2012-09-13T18:00:00+02:00","EndDate":"2012-09-14T04:00:00+02:00","Cls":"","Name":"Secret task","Id":10,"ResourceId":15}}
server responds with :
{"data":[{"Name":"Secret task","Id":10,"StartDate":"2012-09-13T18:00:00+02:00","EndDate":"2012-09-14T04:00:00+02:00","ResourceId":15,"Resizable":null,"Draggable":null,"Cls":""}]}
in which the boolean properties are nulled. I've tried ignoring the setter for this field but without any luck. I also had to remove nullable=false as with this included I was getting an error :
org.springframework.dao.DataIntegrityViolationException: not-null property references a null or transient value: model.Event.draggable; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value: model.Event.draggable
This is my MySQL table definition :
CREATE TABLE IF NOT EXISTS `events` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`Name` varchar(255) DEFAULT NULL,
`StartDate` varchar(50) DEFAULT NULL,
`EndDate` varchar(50) DEFAULT NULL,
`ResourceId` int(11) DEFAULT NULL,
`Resizable` tinyint(1) DEFAULT NULL,
`Draggable` tinyint(1) DEFAULT NULL,
`Cls` varchar(255) DEFAULT NULL,
PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ;
And this is the model code :
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonIgnore;
#JsonAutoDetect
#JsonIgnoreProperties(ignoreUnknown = true)
#Entity
#Table(name="events")
public class Event {
#Id
#GeneratedValue
#Column(name="Id")
private int id;
#Column(name="Name", nullable=false)
private String name;
#Column(name="StartDate", nullable=false)
private String startDate;
#Column(name="EndDate", nullable=false)
private String endDate;
#Column(name="ResourceId", nullable=false)
private int resourceId;
#Column(name="Resizable")
private Boolean resizable;
#Column(name="Draggable")
private Boolean draggable;
#Column(name="Cls", nullable=false)
private String cls;
#JsonProperty("Id")
public int getId() {
return id;
}
#JsonProperty("Id")
public void setId(int id) {
this.id = id;
}
#JsonProperty("Name")
public String getName() {
return name;
}
#JsonProperty("Name")
public void setName(String name) {
this.name = name;
}
#JsonProperty("StartDate")
public String getStartDate() {
return startDate;
}
#JsonProperty("StartDate")
public void setStartDate(String start) {
this.startDate = start;
}
#JsonProperty("EndDate")
public String getEndDate() {
return endDate;
}
#JsonProperty("EndDate")
public void setEndDate(String end) {
this.endDate = end;
}
#JsonProperty("ResourceId")
public int getResourceId() {
return resourceId;
}
#JsonProperty("ResourceId")
public void setResourceId(int id) {
this.resourceId = id;
}
#JsonProperty("Resizable")
public Boolean getResizable() {
return resizable;
}
#JsonIgnore
public void setResizable(Boolean resizable) {
this.resizable = resizable;
}
#JsonProperty("Draggable")
public Boolean getDraggable() {
return draggable;
}
#JsonIgnore
public void setDraggable(Boolean draggable) {
this.draggable = draggable;
}
#JsonProperty("Cls")
public String getCls() {
return cls;
}
#JsonProperty("Cls")
public void setCls(String cls) {
this.cls = cls;
}
}
Is there anything I can do to prevent this behaviour ?
You are explicitly telling Jackson to ignore the two properties you mentioned, when deserializing your object from its JSON representation. This:
#JsonIgnore
public void setDraggable(Boolean draggable) {
this.draggable = draggable;
}
#JsonIgnore
public void setResizable(Boolean resizable) {
this.resizable = resizable;
}
Basically means, ignore these properties when deserializing from my JSON data. So, consequently when you save your object those properties are null in the database.
You can simply do this:
public boolean getResizable() {
return resizable != null && resizable;
}

one to many hibernate

Hi I am trying to do one to many insert but I am having problems.
I have two tables:
CREATE TABLE users_app (
user_id int UNSIGNED NOT NULL AUTO_INCREMENT,
user_number varchar(45) NOT NULL default '0',
user_password varchar(45) NOT NULL default '0',
os int(1) unsigned NOT NULL,
token varchar(500) NOT NULL,
PRIMARY KEY (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8;
CREATE TABLE user_app_devices(
id int AUTO_INCREMENT PRIMARY KEY,
user_id int UNSIGNED NOT NULL,
device_name varchar(45) NOT NULL,
FOREIGN KEY (user_id) REFERENCES users_app (user_id)
)ENGINE=InnoDB CHARSET=utf8;
My classes:
#Entity
#Table(name="user_app_devices")
public class UserAppDevice implements Serializable {
private static final long serialVersionUID = 1L;
#Id
private int id;
#Column(name="device_name")
private String deviceName;
//bi-directional many-to-one association to UsersApp
#ManyToOne
#JoinColumn(name="user_id")
private UsersApp usersApp;
public UserAppDevice() {
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public String getDeviceName() {
return this.deviceName;
}
public void setDeviceName(String deviceName) {
this.deviceName = deviceName;
}
public UsersApp getUsersApp() {
return this.usersApp;
}
public void setUsersApp(UsersApp usersApp) {
this.usersApp = usersApp;
}
}
#Entity
#Table(name="users_app")
public class UsersApp implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#Column(name="user_id")
private int userId;
private int os;
private String token;
#Column(name="user_number")
private String userNumber;
#Column(name="user_password")
private String userPassword;
//bi-directional many-to-one association to UserAppDevice
#OneToMany(mappedBy="usersApp")
private List<UserAppDevice> userAppDevices;
public UsersApp() {
}
public int getUserId() {
return this.userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public int getOs() {
return this.os;
}
public void setOs(int os) {
this.os = os;
}
public String getToken() {
return this.token;
}
public void setToken(String token) {
this.token = token;
}
public String getUserNumber() {
return this.userNumber;
}
public void setUserNumber(String userNumber) {
this.userNumber = userNumber;
}
public String getUserPassword() {
return this.userPassword;
}
public void setUserPassword(String userPassword) {
this.userPassword = userPassword;
}
public List<UserAppDevice> getUserAppDevices() {
return this.userAppDevices;
}
public void setUserAppDevices(List<UserAppDevice> userAppDevices) {
this.userAppDevices = userAppDevices;
}
public UsersApp(int os, String token, String userNumber, String userPassword) {
this.os = os;
this.token = token;
this.userNumber = userNumber;
this.userPassword = userPassword;
}
I want to add new user with device
I try this code:
Session session = (Session) em.getDelegate();
session.beginTransaction();
UsersApp user = new UsersApp(os, token, userNumber, userPassword);
session.save(user);
UserAppDevice ud = new UserAppDevice();
ud.setUsersApp(user);
ud.setDeviceName(device);
session.save(ud);
session.getTransaction().commit();
but I am facing exception:
13:16:48,516 WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http--0.0.0.0-8080-3) SQL Error: 1452, SQLState: 23000
13:16:48,517 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http--0.0.0.0-8080-3) Cannot add or update a child row: a foreign key constraint fails (`application`.`user_a
pp_devices`, CONSTRAINT `user_app_devices_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users_app` (`user_id`))
13:16:48,520 ERROR [org.jboss.as.ejb3.tx.CMTTxInterceptor] (http--0.0.0.0-8080-3) javax.ejb.EJBTransactionRolledbackException: Cannot add or update a child row: a foreign key const
raint fails (`application`.`user_app_devices`, CONSTRAINT `user_app_devices_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users_app` (`user_id`))
13:16:48,524 ERROR [org.jboss.ejb3.invocation] (http--0.0.0.0-8080-3) JBAS014134: EJB Invocation failed on component DeviceRegisterDAOImpl for method public abstract void com.break
id.ejb.model.DeviceRegisterDAO.add(int,java.lang.String,java.lang.String,java.lang.String,java.lang.String): javax.ejb.EJBTransactionRolledbackException: Cannot add or update a chi
ld row: a foreign key constraint fails (`application`.`user_app_devices`, CONSTRAINT `user_app_devices_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users_app` (`user_id`))
at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleInCallerTx(CMTTxInterceptor.java:139) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInCallerTx(CMTTxInterceptor.java:204) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:306) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:190) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
at org.jboss.as.ejb3.remote.EJBRemoteTransactionPropagatingInterceptor.processInvocation(EJBRemoteTransactionPropagatingInterceptor.java:80) [jboss-as-ejb3-7.1.1.Final.jar:
7.1.1.Final]
What am I missing ?
You haven't told Hibernate that the ID of UserApp was generated automatically by the database:
#Id
#GeneratedValue(strategy = IDENTITY)
#Column(name="user_id")
private int userId;
(and do the same for the other entity)
Since your are using bidirectional, change your client code as below.
Session session = (Session) em.getDelegate();
session.beginTransaction();
UserAppDevice ud = new UserAppDevice();
ud.setDeviceName(device);
UsersApp user = new UsersApp(os, token, userNumber, userPassword);
user.setUserAppDevices(new ArrayList<UserAppDevice>())
user.getUserAppDevices().add(ud);
session.save(user);
session.getTransaction().commit();
As mentioned by JB Nizet, you're missing the autogenerated strategy.
An alternative would be to use UUID as your id column and create the values yourself with
#Id
private UUID id = UUID.randomUUID();
Also, don't forget to set equals/hashCode to use the id field as discussed to death in The JPA hashCode() / equals() dilemma
Incidentally, why are you using Session (hibernate specific) instead of sticking to JPA's API?

Simple object persist in Spring + hibernate

I suppose it is not standard way of doing that so any tips will be helpful, here is my code:
#RequestMapping("/register")
public String register(Map<String, Object> map, #ModelAttribute("user") MyUser user) {
if(user.getLogin() == ""){
map.put("user", new MyUser());
}
else{
map.put("user", user);
map.put("result", userService.addMyUser(user));
}
return "register";
}
what cause following error:
org.hibernate.AssertionFailure: null id in org.mypackage.MyUser entry
(don't flush the Session after an exception occurs)
Here is MyUser class:
#Entity
#Table(name="MyUser")
public class MyUser{
#Id
#Column(name="idMyUser")
#GeneratedValue
private Integer id;
#Column(name="login")
private String login;
#Column(name="password")
private String password;
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
Try changing the strategy and/or generator for the #GeneratedValue, see here and here for details (for example, you could try #GeneratedValue(strategy = GenerationType.IDENTITY). You could also check if your database table is set to generate the primary key values. The exception seems to indicate that the primary key -field is left unset by the current strategy and/or generator.

Categories

Resources