I have problem in a JPA entity class. This entity was working perfectly as it should but today
i added another field (a simple string, varchar(255) NOT NULL in the database). When I try to persist a new entity i get an
java.sql.SQLException: Field 'companyLogoUrl' doesn't have a default value
Well, this is true. The column does not have a default value. but in my code i set the value for it. When I have a look at the generated insert statement the field is not present.
INSERT INTO COMPANY (ACCOUNTNUMBER, ACCOUNTOWNER, BANK, BANKCODE, CHANGEDAT,
COMPANYNAME, CREATEDAT, addressId)
The name of the variable matches the the column-name so there are no annotations which could cause the error. It is treated just like the other fields/columns which work fine.
Thanks in advance for any help!
EDIT:
Here is the class (a groovy-class):
@Entity
class Company extends KupiumEntity
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
final int companyId
String companyName
String bank
String bankCode
String accountNumber
String accountOwner
String companyLogoUrl
@ManyToOne(cascade=CascadeType.PERSIST)
@JoinColumn(name="addressId")
Address address = new Address()
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name="companyId")
List<Invoice> invoices = new ArrayList<Invoice>()
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name="companyId")
List<Kupon> kupons = new ArrayList<Kupon>()
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name="mandatorId")
List<Mandator> mandators = new ArrayList<Mandator>()
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name="companyAppId")
List<CompanyApp> companyApps = new ArrayList<CompanyApp>()
}
EDIT 2:
Sorry for the confusion. The field and the column in the table are named ‘companyLogoUrl’
Well, I solved this issue today, though i am still not aware what the cause is.
I tried to run my unitTests and these told me that they could not find the pom.xml in this project. This was somehow surprising since it is no Maven-Project so I do not understand why he was even looking for it. Anyway, I created a new Project, copied the source from the old to the new one and… it works.
I still find it hard to figure out why eclipse would even think about it as a maven project (why else would he look for a pom.xml?)
And again I apologize for the confusion about the names of fields/columns. Thanks for your help, guys!