I created the following table within the catalog "data" that requires to reference an entity called "UserAccount" in a different catalog namely, "useraccount". So I write:
@Entity
@Table(name = "data", catalog = "data")
public class Data implements Serializable
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false, unique = true)
private String name;
@ManyToOne(targetEntity = UserAccount.class)
@PrimaryKeyJoinColumn
private UserAccount user;
....//
}
But using "targetEntity" parameter seems not working since I get the following error:
@OneToOne or @ManyToOne on [cut].Data.user references an unknown entity: [cut].user.UserAccount
Hence, the reference is not right. How to correctly refer to entities from another catalog?
Edit. For catalog I mean Database schema:
Edit: One of the configuration file
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
entityManagerFactoryRef = "userEntityManager",
transactionManagerRef = "userTransactionManager",
basePackages = {"it.unict.spring.platform.persistence.repository.user"}
)
public class JpaTransactUser
{
@Bean(name = "userEntityManager")
public LocalContainerEntityManagerFactoryBean getServersEntityManager(
EntityManagerFactoryBuilder builder,
@Qualifier("userSource") DataSource serversDataSource){
return builder
.dataSource(serversDataSource)
.packages("it.unict.spring.platform.persistence.model.user")
.persistenceUnit("userUnit")
.properties(additionalJpaProperties())
.build();
}
Map<String,?> additionalJpaProperties()
{
Map<String,String> map = new HashMap<>();
map.put("hibernate.hbm2ddl.auto", "update");
//map.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
map.put("hibernate.show_sql", "true");
return map;
}
@Bean("userDataSourceProperties")
@ConfigurationProperties("app.datasource.user")
public DataSourceProperties dataDataSourceProperties()
{
return new DataSourceProperties();
}
@Bean("userSource")
@ConfigurationProperties("app.datasource.user")
public DataSource getDataSource(@Qualifier("userDataSourceProperties") DataSourceProperties dataDataSourceProperties) {
return dataDataSourceProperties().initializeDataSourceBuilder().build();
}
@Bean(name = "userTransactionManager")
public JpaTransactionManager transactionManager(@Qualifier("userEntityManager") EntityManagerFactory serversEntityManager)
{
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(serversEntityManager);
return transactionManager;
}
}