When I run the application, I get the error:

org.hibernate.PropertyNotFoundException: Could not find a getter for delayModule in class com.project.core.hibernate.entities.DBReadFilesEntity

The following settings are in the guavacached.hbm.xml file:

<class name="com.project.core.hibernate.entities.DBReadFilesEntity" table="read_files" catalog="newserver" mutable="false"> <id name="id"> <column name="id" sql-type="int unsigned" not-null="true"/> </id> ... <property name="delayerModulesId"> <column name="delayer_modules_id" sql-type="int unsigned" not-null="true"/> </property> <property name="delayerParams"> <column name="delayer_params" sql-type="varchar" not-null="true"/> </property> ... <many-to-one insert="false" update="false" name="delayerModule" class="com.project.core.hibernate.entities.DBModulesEntity"> <column name="delayer_modules_id" not-null="true"/> </many-to-one> ... </class> 

And the DBReadFilesEntity class itself :

 @Entity @Table(catalog = "newserver", name = "read_files") @Cache(usage = CacheConcurrencyStrategy.READ_ONLY) @org.hibernate.annotations.Entity(mutable = false) public class DBReadFilesEntity { private int id; @Id @Column(name = "id") public int getId() { return id; } public void setId(int id) { this.id = id; } ... private int delayerModulesId; @Basic @Column(name = "delayer_modules_id") public int getDelayerModulesId() { return delayerModulesId; } public void setDelayerModulesId(int delayerModulesId) { this.delayerModulesId = delayerModulesId; } private String delayerParams; @Basic @Column(name = "delayer_params") public String getDelayerParams() { return delayerParams; } public void setDelayerParams(String delayerParams) { this.delayerParams = delayerParams; } ... } 

And the read_files table schema :

 CREATE TABLE `read_files` ( `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, ..., `delayer_modules_id` INT(10) UNSIGNED NOT NULL DEFAULT '4001', `delayer_params` VARCHAR(255) NOT NULL DEFAULT '', ..., PRIMARY KEY (`id`), ..., KEY `FK_read_files_delayer_id` (`delayer__modules_id`), ..., CONSTRAINT `FK_read_files_delayer_id` FOREIGN KEY (`delayer_modules_id`) REFERENCES `modules` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE, ... ) ENGINE=INNODB AUTO_INCREMENT=4 DEFAULT CHARSET=cp1251 

What is the mistake?

  • one
    <many-to-one name="delayerModule" ... apparently many links to one are made incorrectly. - MrFylypenko

1 answer 1

Strange mapping you have, you have a delayerModulesId field, but you also have a delayerModule field associated with delayer_modules_id (the hyber itself actually swears that it is not in the class).

If you wanted to specify the connection of the delayerModulesId field with the id in another table, then you need to correct it like this:

This is to remove:

 <property name="delayerModulesId"> <column name="delayer_modules_id" sql-type="int unsigned" not-null="true"/> </property> 

And fix it:

  <many-to-one insert="false" update="false" name="delayerModulesId" class="com.project.core.hibernate.entities.DBModulesEntity"> <column name="delayer_modules_id" not-null="true"/> </many-to-one> 

Also, when links are in a class, instead of this field, an object of the class of the table to which it refers will be stored:

 private DBModulesEntity delayerModulesId; 

PS And honestly, you need to OR use xml mapping or annotations. Both methods do not need to be applied. (And in new versions of xml, the mapping would seem to be excluded)

PSS You in mapping can, in principle, not specify the presence of links, if you do not need explicit references to the associated object.