I need some help with a strange error : "Fabricationfolder is not mapped".
Here is the context :
I Have a project "war" which includes a library "jar". Both of them has entity on two separated schema MariaDB.
I cannot change anything to the jar because, it's used by other projects.
I'm using the same hibernate version for both : 4.1.7 and spring 4.
For some reasons, I need to link some entities of my war to the jar entities. In order to add attributes to jar's entity, I decided to extends some entities of the jar into my war.
Is it a good way?
When I'm launching the web, app, the first request on Fabricationfolder fails with this error.
Here ares the configuration :
Schema :
Code:
CREATE DATABASE IF NOT EXISTS sampledb
CHARACTER SET latin1
COLLATE latin1_swedish_ci;
USE sampledb;
CREATE TABLE IF NOT EXISTS fabricationfolder (
id_folder INT(11) NOT NULL,
id_product_type INT(11) NOT NULL,
folder_number VARCHAR(15) NOT NULL,
customer_code VARCHAR(15) NOT NULL,
customer_name VARCHAR(32) NOT NULL,
brand VARCHAR(32) NOT NULL,
creation_date DATETIME NOT NULL,
bat VARCHAR(1) NOT NULL,
grouped VARCHAR(1) NOT NULL,
fabrication_limit_date DATETIME NOT NULL,
classification VARCHAR(15) DEFAULT NULL,
observation VARCHAR(250) DEFAULT NULL,
status VARCHAR(30) DEFAULT NULL,
height DECIMAL(7, 2) DEFAULT NULL,
flag_height INT(1) NOT NULL,
width DECIMAL(7, 2) DEFAULT NULL,
flag_width INT(1) NOT NULL,
intermediate_code VARCHAR(15) DEFAULT NULL,
date_update DATE DEFAULT NULL,
user_update VARCHAR(20) DEFAULT NULL,
assignment VARCHAR(15) DEFAULT NULL,
id_user_commercial INT(11) NOT NULL,
id_group_commercial INT(11) NOT NULL,
id_group_scheduling INT(11) DEFAULT NULL,
id_group_pilotage INT(11) DEFAULT NULL,
PRIMARY KEY (id_folder),
INDEX id_product_type (id_product_type)
)
ENGINE = INNODB
AVG_ROW_LENGTH = 1365
CHARACTER SET latin1
COLLATE latin1_swedish_ci;
CREATE schema security;
CREATE TABLE security.group (grp_id BIGINT AUTO_INCREMENT NOT NULL, grp_name VARCHAR(150) NOT NULL, PRIMARY KEY (grp_id));
CREATE TABLE security.user (usr_id BIGINT AUTO_INCREMENT NOT NULL, usr_creation TIMESTAMP, usr_email VARCHAR(128), usr_enabled BOOLEAN NOT NULL, usr_expiration TIMESTAMP, usr_firstname VARCHAR(50), usr_lastname VARCHAR(50), usr_modification TIMESTAMP, usr_password VARCHAR(100) NOT NULL, usr_login VARCHAR(128) NOT NULL, PRIMARY KEY (usr_id));
Entity Fabricationfolder in war, package com.sp.sfc.business.model
Code:
@Entity
@Table(name = "fabricationfolder")
public class Fabricationfolder implements java.io.Serializable {
private int idFolder;
private ProductType productType;
private String folderNumber;
private String customerCode;
private String customerName;
private String brand;
private Date creationDate;
private String bat;
private String grouped;
private Date endDate;
private String classification;
private String observation;
private String status;
private Double height;
private Double width;
private boolean flagHeight;
private boolean flagWidth;
private String intermediateCode;
private Date dateUpdate;
private String userUpdate;
private String assignment;
private User userCommercial;
private Group groupCommercial;
private Group groupScheduling;
private Group groupPilotage;
private List<Publication> publications = new ArrayList<Publication>();
private List<Message> messages = new ArrayList<Message>();
private List<Element> elements = new ArrayList<Element>();
public Fabricationfolder() {
}
@Id
@Column(name = "id_folder", unique = true, nullable = false)
public int getIdFolder() {
return this.idFolder;
}
public void setIdFolder(int idFolder) {
this.idFolder = idFolder;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id_product_type", nullable = false)
public ProductType getProductType() {
return this.productType;
}
public void setProductType(ProductType productType) {
this.productType = productType;
}
@Column(name = "folder_number", nullable = false, length = 15)
public String getFolderNumber() {
return this.folderNumber;
}
public void setFolderNumber(String folderNumber) {
this.folderNumber = folderNumber;
}
@Column(name = "customer_code", nullable = false, length = 15)
public String getCustomerCode() {
return this.customerCode;
}
public void setCustomerCode(String customerCode) {
this.customerCode = customerCode;
}
@Column(name = "customer_name", nullable = false, length = 32)
public String getCustomerName() {
return this.customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
@Column(name = "brand", nullable = false, length = 32)
public String getBrand() {
return this.brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "creation_date", nullable = false, length = 19)
public Date getCreationDate() {
return this.creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
@Column(name = "bat", nullable = false, length = 1)
public String getBat() {
return this.bat;
}
public void setBat(String bat) {
this.bat = bat;
}
@Column(name = "grouped", nullable = false, length = 1)
public String getGrouped() {
return this.grouped;
}
public void setGrouped(String grouped) {
this.grouped = grouped;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "fabrication_limit_date", nullable = false, length = 19)
public Date getEndDate() {
return this.endDate;
}
public void setEndDate(Date fabricationLimitDate) {
this.endDate = fabricationLimitDate;
}
@Column(name = "classification", length = 15)
public String getClassification() {
return this.classification;
}
public void setClassification(String classification) {
this.classification = classification;
}
@Column(name = "observation", length = 250)
public String getObservation() {
return this.observation;
}
public void setObservation(String observation) {
this.observation = observation;
}
@Column(name = "status", length = 30)
public String getStatus() {
return this.status;
}
public void setStatus(String status) {
this.status = status;
}
@Column(name = "height")
public Double getHeight() {
return this.height;
}
@Column(name = "height")
public void setHeight(Double height) {
this.height = height;
}
@Column(name = "width", precision = 7)
public Double getWidth() {
return this.width;
}
public void setWidth(Double width) {
this.width = width;
}
@Column(name = "intermediate_code", length = 15)
public String getIntermediateCode() {
return this.intermediateCode;
}
public void setIntermediateCode(String intermediateCode) {
this.intermediateCode = intermediateCode;
}
@Temporal(TemporalType.DATE)
@Column(name = "date_update", length = 10)
public Date getDateUpdate() {
return this.dateUpdate;
}
public void setDateUpdate(Date dateUpdate) {
this.dateUpdate = dateUpdate;
}
@Column(name = "user_update", length = 20)
public String getUserUpdate() {
return this.userUpdate;
}
public void setUserUpdate(String userUpdate) {
this.userUpdate = userUpdate;
}
@Column(name = "assignment", length = 15)
public String getAssignment() {
return this.assignment;
}
public void setAssignment(String assignment) {
this.assignment = assignment;
}
@OrderBy("publicationDate ASC")
@OneToMany(fetch = FetchType.LAZY, mappedBy = "fabricationfolder")
public List<Publication> getPublications() {
return this.publications;
}
public void setPublications(List<Publication> publications) {
this.publications = publications;
}
public void setMessages(List<Message> messages) {
this.messages = messages;
}
@OrderBy("creationDate ASC")
@OneToMany(fetch = FetchType.LAZY, mappedBy = "fabricationfolder")
public List<Element> getElements() {
return this.elements;
}
public void setElements(List<Element> elements) {
this.elements = elements;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id_user_commercial", nullable = true, referencedColumnName= "usr_id")
public User getUserCommercial() {
return userCommercial;
}
public void setUserCommercial(User userCommercial) {
this.userCommercial = userCommercial;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id_group_commercial", nullable = true, referencedColumnName= "grp_id")
public Group getGroupCommercial() {
return groupCommercial;
}
public void setGroupCommercial(Group groupCommercial) {
this.groupCommercial = groupCommercial;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id_group_scheduling", nullable = true, referencedColumnName= "grp_id")
public Group getGroupScheduling() {
return groupScheduling;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "fabricationfolder")
public List<Message> getMessages() {
return messages;
}
public void setGroupScheduling(Group groupScheduling) {
this.groupScheduling = groupScheduling;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id_group_pilotage", nullable = true, referencedColumnName= "grp_id")
public Group getGroupPilotage() {
return groupPilotage;
}
public void setGroupPilotage(Group groupPilotage) {
this.groupPilotage = groupPilotage;
}
@Column(name = "flag_height", nullable = false)
public boolean isFlagHeight() {
return flagHeight;
}
public void setFlagHeight(boolean flagHeight) {
this.flagHeight = flagHeight;
}
@Column(name = "flag_width", nullable = false)
public boolean isFlagWidth() {
return flagWidth;
}
public void setFlagWidth(boolean flagWidth) {
this.flagWidth = flagWidth;
}
}
User and Group extends :
Code:
@Entity
public class User extends SPUser {
public User(String login, String pass, String email) {
super(login, pass, email);
}
public List<Group> getUserGroups(){
List<Group> listGroup = new ArrayList<Group>();
for(SPGroup agroup: getGroups()){
listGroup.add((Group)agroup);
}
return listGroup;
}
}
@Entity
public class Group extends SPGroup {
public Group(String groupName) {
super(groupName);
}
}
Entities User And Group of jar package com.sfc.security.metier.impl :
Code:
@Entity
@Table(name="group", schema="security")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class SPGroup implements Group {
@Id
@GeneratedValue
@Column(name = "grp_id", unique = true, nullable = false)
private Long id;
@Column(name = "grp_name", unique = true, nullable = false, length=150)
private String name;
@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinTable(name = "group_user", schema="security", joinColumns = {
@JoinColumn(name = "grp_id", nullable = false, updatable = false) },
inverseJoinColumns = { @JoinColumn(name = "usr_id",
nullable = false, updatable = false) })
private List<SPUser> users = new ArrayList<SPUser>();
@ManyToMany(fetch = FetchType.LAZY, mappedBy = "childGroups")
private List<SPGroup> parentGroups = new ArrayList<SPGroup>();
@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinTable(name = "group_group", schema="security", joinColumns = {
@JoinColumn(name = "parent_id", nullable = false, updatable = false, referencedColumnName="grp_id") },
inverseJoinColumns = { @JoinColumn(name = "child_id",
nullable = false, updatable = false, referencedColumnName="grp_id") })
private List<SPGroup> childGroups = new ArrayList<SPGroup>();
@OneToMany(fetch = FetchType.LAZY, targetEntity=RoleTag.class ,mappedBy = "group", cascade={CascadeType.ALL})
private List<RoleTag> roleTags = new ArrayList<RoleTag>();
@OneToMany(fetch = FetchType.LAZY, targetEntity=PermissionTag.class, mappedBy = "group", cascade={CascadeType.ALL})
private List<PermissionTag> permissionTags = new ArrayList<PermissionTag>();
...
}
@Entity@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(name="user", schema="security")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class SPUser implements User {
private static final long serialVersionUID = 6335411953406117295L;
@Id
@GeneratedValue
@Column(name = "usr_id", unique = true, nullable = false)
private Long id;
@Column(name = "usr_password", nullable = false, length=100)
private String password;
@Column(name = "usr_login", unique=true, nullable = false, length=128)
private String username;
@Column(name = "usr_enabled", nullable = false)
private boolean enabled;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "usr_expiration")
private Date expirationDate;
@Column(name = "usr_firstname", length=50)
private String firstname;
@Column(name = "usr_lastname", length=50)
private String lastname;
@Column(name = "usr_email", unique=true, length=128)
private String email;
@CreatedDate
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "usr_creation")
private Date creationDate;
@LastModifiedDate
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "usr_modification")
private Date modificationDate;
@ManyToMany(fetch = FetchType.LAZY, mappedBy = "users")
private List<SPGroup> groups;
...
}
And the configuration for hibernate war :
Code:
@Configuration
@EnableTransactionManagement
@ComponentScan("com.sp.sfc.business")
@PropertySource("classpath:properties/${environnement:prod}/application.properties")
public class WebBusinessConfig implements TransactionManagementConfigurer {
@Bean
public DataSource businessDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/sampledb");
dataSource.setUsername("user");
dataSource.setPassword("pass");
return dataSource;
}
@Bean
public LocalSessionFactoryBean businessSessionFactory() {
LocalSessionFactoryBean sessionFactoryBean = new LocalSessionFactoryBean();
sessionFactoryBean.setDataSource(businessDataSource());
sessionFactoryBean.setPackagesToScan("com.sp.sfc.business.model,com.sfc.security.metier.impl");
sessionFactoryBean.setHibernateProperties(hibProperties());
return sessionFactoryBean;
}
private Properties hibProperties() {
Properties properties = new Properties();
properties.put(hibernate.dialect, "org.hibernate.dialect.MySQLDialect");
properties.put(hibernate.show_sql, "true");
return properties;
}
@Bean
public HibernateTransactionManager hibernateBusinessTransactionManager() {
HibernateTransactionManager transactionManager = new HibernateTransactionManager();
transactionManager.setSessionFactory(businessSessionFactory().getObject());
return transactionManager;
}
@Override
public PlatformTransactionManager annotationDrivenTransactionManager() {
return hibernateBusinessTransactionManager();
}
}
And jar configuration
Code:
<tx:annotation-driven transaction-manager="transactionManagersfcSecurity" />
<jpa:repositories base-package="com.sfc.security.repositories" entity-manager-factory-ref="entityManagerFactorysfcSecurity" transaction-manager-ref="transactionManagersfcSecurity"/>
<bean id="entityManagerFactorysfcSecurity" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSourcesfcSecurity"/>
<property name="packagesToScan" value="com.sfc.security.metier.impl" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" >
<property name="showSql" value="false"/>
</bean>
</property>
<property name="persistenceXmlLocation" value="classpath:data/security/security-persistence.xml"/>
<property name="jpaPropertyMap" ref="$HibernateConfigurationsfcSecurity"/>
</bean>
<util:map id="HibernateConfigurationsfcSecurity" >
<entry key="hibernate.generateDdl" value="false" />
<entry key="hibernate.databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
<entry key="hibernate.current_session_context_class" value="thread" />
</util:map>
<bean id="dataSourcesfcSecurity" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://127.0.0.1:3306/sampledb" />
<property name="username" value="user" />
<property name="password" value="pass" />
<property name="defaultAutoCommit" value="false" />
</bean>
<bean id="transactionManagersfcSecurity" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactorysfcSecurity" />
</bean>
security-persistence.xml of jar (there is no one in war)
Code:
<persistence-unit name="security" >
<provider>org.hibernate.ejb.HibernatePersistence</provider>
</persistence-unit>
Thanks for your help