I'm not sure why Spring boot doesn't recognize my second data source which I think is configured right.
I'm keep getting this message: ...Error creating bean with name 'leadRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class com.ref.api.test.lead.model.LeadEntity
I setted the right path for.packages("com.ref.api.test.lead.model") but for some reason spring-boot don't check my entity there.
PrimaryDsConfig
#Configuration
#EnableTransactionManagement
#EnableJpaRepositories(
entityManagerFactoryRef = "entityManagerFactory",
basePackages = { "com.ref.api.repository" }
)
public class PrimaryDsConfig {
#Primary
#Bean(name = "dataSource")
#ConfigurationProperties(prefix = "spring.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
#Primary
#Bean(name = "entityManagerFactory")
public LocalContainerEntityManagerFactoryBean
entityManagerFactory(
EntityManagerFactoryBuilder builder,
#Qualifier("dataSource") DataSource dataSource
) {
return builder
.dataSource(dataSource)
.packages("com.ref.api.model")
.persistenceUnit("foo")
.build();
}
#Primary
#Bean(name = "transactionManager")
public PlatformTransactionManager transactionManager(
#Qualifier("entityManagerFactory") EntityManagerFactory
entityManagerFactory
) {
return new JpaTransactionManager(entityManagerFactory);
}
}
AdditionDsConfig
#Configuration
#EnableTransactionManagement
#EnableJpaRepositories(
entityManagerFactoryRef = "barEntityManagerFactory",
transactionManagerRef = "barTransactionManager",
basePackages = { "com.ref.api.test.lead.repository" }
)
public class AdditionDsConfig {
#Bean(name = "barDataSource")
#ConfigurationProperties(prefix = "addition.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
#Bean(name = "barEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean
barEntityManagerFactory(
EntityManagerFactoryBuilder builder,
#Qualifier("barDataSource") DataSource dataSource
) {
return
builder
.dataSource(dataSource)
.packages("com.ref.api.test.lead.model")
.persistenceUnit("bar")
.build();
}
#Bean(name = "barTransactionManager")
public PlatformTransactionManager barTransactionManager(
#Qualifier("barEntityManagerFactory") EntityManagerFactory
barEntityManagerFactory
) {
return new JpaTransactionManager(barEntityManagerFactory);
}
application.yml
spring:
datasource:
jdbc-url: jdbc:postgresql://blabla..
username: bla
password: bla
addition:
datasource:
jdbc-url: jdbc:postgresql://blabla2..
username: bla2
password: bla2
LeadEntity
package com.ref.api.test.lead.model;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import javax.persistence.*;
import java.io.Serializable;
#Entity
#Table(name = "lead")
#AllArgsConstructor
#NoArgsConstructor
#Getter
#Setter
#SequenceGenerator(name = "lead_id_seq",
sequenceName = "lead_id_seq",
allocationSize = 1)
public class LeadEntity implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "lead_id_seq")
private Long lead_id;
private String place_id;
private String name;
private String formatted_address;
private String country;
private String state;
private String city;
private String postal_code;
private String formatted_phone_number;
private String international_phone_number;
private String website;
private String vicinity;
private String rating;
private String price_level;
private String lat;
private String lng;
private String types;
private String place_url;
private String utc_offset;
private String opening_hours;
private String email;
private String logo;
}
LeadRepository
package com.ref.api.test.lead.repository;
import com.ref.api.test.lead.model.LeadEntity;
import org.springframework.data.jpa.repository.JpaRepository;
public interface LeadRepository extends JpaRepository<LeadEntity, Long> {
}
ApiApplication
#SpringBootApplication
#EnableJpaRepositories(repositoryFactoryBeanClass = EntityGraphJpaRepositoryFactoryBean.class)
#EnableCaching
public class ApiApplication {
I figure out why spring-boot didn't detect my second datasource.
Beacuse I had #EnableJpaRepositories on my public class ApiApplication so it was confused.
When I moved repositoryFactoryBeanClass = EntityGraphJpaRepositoryFactoryBean.class to my PrimaryDsConfig everything starting working.
So just pay attention how many #EnableJpaRepositories do you have.
Related
Currently I have to connect two Oracle Datasources in my Spring Boot proyect. I think that I did well the configuration because Spring validated my connection but when I call a service this always response me "Empty". I think is because the TransactionManager don't change.
This is my project structure:
- project
⊢---- config
⊢---- controllers
∟---- models
⊢---- dao
| ⊢---- db1
| ∟---- db2
⊢---- entity
| ⊢---- db1
| ∟---- db2
⊢---- services
⊢---- db1
∟---- db2
This are my entities classes:
package project.models.entity.db1;
//// IMPORTS
#Entity(name = "User")
#Table(name = "T_USER")
public class User implements Serializable {
private static final long serialVersionUID = 1L;
#Id
private Long id;
private String name;
private String surname;
private String username;
private String password;
////// CONSTRUCT
////// GETTERS & SETTERS
////// HASCODE, EQUALS AND TOSTRING
}
package project.models.entity.db2;
//// IMPORTS
#Entity(name = "Shareholder")
#Table(name = "Shareholder")
public class Shareholder implements Serializable {
private static final long serialVersionUID = 1L;
#Id
private Integer id;
private Integer numberTitles;
////// CONSTRUCT
////// GETTERS & SETTERS
////// HASCODE, EQUALS AND TOSTRING
}
This are my repositories classes:
package project.models.dao.db1;
//// IMPORTS
#PersistenceContext(name = "db1")
#Repository
public interface IUserDao extends JpaRepository<User, Long> {
}
package project.models.dao.db2;
//// IMPORTS
#PersistenceContext(name = "db2")
#Repository
public interface IShareholderDao extends JpaRepository<Shareholder, Integer> {
}
This are my services classes:
package project.models.services.db1.impl;
//// IMPORTS
#Service
public class UserServiceImpl implements IUserService {
#Autowired
private IUserDao userDao;
#Override
#Transactional("transactionManager")
public List<User> findAll() {
return userDao.findAll();
}
#Override
#Transactional("transactionManager")
public User findById(Long id) {
return userDao.findById(id).orElse(null);
}
package project.models.services.db2.impl;
//// IMPORTS
#Service
public class ShareholderServiceImpl implements IShareholderService {
#Autowired
private IShareholderDao shareholderDao;
#Override
#Transactional("db2TransactionManager")
public List<Shareholder> findAll() {
return shareholderDao.findAll();
}
#Override
#Transactional("db2TransactionManager")
public Shareholder findById(Integer id) {
return shareholderDao.findById(id).orElse(null);
}
}
And this are my config classes:
package project.config;
//// IMPORTS
#Configuration
#ConfigurationProperties(prefix = "oracle1")
#EnableJpaRepositories(entityManagerFactoryRef = "entityManagerFactory", transactionManagerRef = "transactionManager", basePackages = {
"project.models.dao.db1" })
#EnableTransactionManagement
#Validated
public class Db1Config {
#NotNull
private String username;
#NotNull
private String password;
#NotNull
private String url;
#Bean(name = "entityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactory() throws SQLException {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
em.setPackagesToScan(new String[] { "project.models.entity.db1" });
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
em.setJpaProperties(hibernateProperties());
em.setPersistenceUnitName("db1");
return em;
}
#Bean(name = "dataSource")
DataSource dataSource() throws SQLException {
OracleDataSource dataSource = new OracleDataSource();
dataSource.setUser(username);
dataSource.setPassword(password);
dataSource.setURL(url);
dataSource.setImplicitCachingEnabled(true);
dataSource.setFastConnectionFailoverEnabled(true);
return dataSource;
}
#Primary
#Bean(name = "transactionManager")
public PlatformTransactionManager transactionManager() throws SQLException {
return new JpaTransactionManager(entityManagerFactory().getObject());
}
private Properties hibernateProperties() {
Properties properties = new Properties();
properties.put("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect");
properties.put("hibernate.show_sql", "true");
properties.put("hibernate.hbm2ddl.auto", "validate");
return properties;
}
}
package project.config;
//// IMPORTS
#Configuration
#ConfigurationProperties(prefix = "oracle2")
#EnableJpaRepositories(entityManagerFactoryRef = "db2EntityManagerFactory", transactionManagerRef = "db2TransactionManager", basePackages = {
"project.models.dao.db2" })
#EnableTransactionManagement
#Validated
public class Db2Config {
#NotNull
private String username;
#NotNull
private String password;
#NotNull
private String url;
#Bean(name = "db2EntityManagerFactory")
public LocalContainerEntityManagerFactoryBean db2EntityManagerFactory() throws SQLException {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(db2DataSource());
em.setPackagesToScan(new String[] { "project.models.entity.db2" });
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
em.setJpaProperties(hibernateProperties());
em.setPersistenceUnitName("db2");
return em;
}
#Bean(name = "db2DataSource")
DataSource db2DataSource() throws SQLException {
OracleDataSource dataSource = new OracleDataSource();
dataSource.setUser(username);
dataSource.setPassword(password);
dataSource.setURL(url);
dataSource.setImplicitCachingEnabled(true);
dataSource.setFastConnectionFailoverEnabled(true);
return dataSource;
}
#Bean(name = "db2TransactionManager")
public PlatformTransactionManager db2TransactionManager() throws SQLException {
return new JpaTransactionManager(db2EntityManagerFactory().getObject());
}
private Properties hibernateProperties() {
Properties properties = new Properties();
properties.put("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect");
properties.put("hibernate.show_sql", "true");
properties.put("hibernate.hbm2ddl.auto", "validate");
return properties;
}
}
And my main application:
package project;
//// IMPORTS
#SpringBootApplication
#EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class })
#EnableCaching
public class ProjectApplication {
#Autowired
private IUserService userService;
#Autowired
private IShareholderService shareholderService;
public static void main(String[] args) {
SpringApplication.run(ProjectApplication.class, args);
}
#PostConstruct
void init() {
List<User> user = userService.findAll();
List<Shareholder> shareholder = shareholderService.findAll();
System.out.println();
System.out.println(user);
System.out.println(shareholder);
System.out.println();
}
}
And always response me:
[User [id=39, name=Jack, surname=Sparrow, ...], [...], ...]
[]
What is the error? Because I don't see it.
Thank you very much
In Db2Config class, package being scanned is different than Db1Config.
Db1Config:
em.setPackagesToScan(new String[] { "project.models.entity.db1" });
Db2Config
em.setPackagesToScan(new String[] { "project.models.dao.db2" });
I have 3 shards(3 different Ips, usernames and passwords). I am using spring boot, spring jpa to save the data in DB. Let's say Customer is my entity. Let's assume, based on some organizationId, I need to insert/update/select the data from different databases.
Current approach :
#Getter
#Setter
#Entity
#Table
#NoArgsConstructor
public class Customer {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Long customerId;
private String firstName;
private String lastName;
private Long organizationId;
}
package lane1;
#Repository
public interface CustomerRepo1 extends CrudRepository<Customer,Long> {
}
package lane2;
#Repository
public interface CustomerRepo2 extends CrudRepository<Customer,Long> {
}
package lane3;
#Repository
public interface CustomerRepo3 extends CrudRepository<Customer,Long> {
}
I am creating 3 datasources(DatasourceLane1, DatasourceLane2, DatasourceLane3) and setting the base packages in the configuration class.
#Configuration
#ConfigurationProperties("DatasourceLane1")
#EnableJpaRepositories(basePackages = "lane1", entityManagerFactoryRef = "lane1EntityManagerFactory",
transactionManagerRef = "lane1TransactionManager")
public class DBConfigurationLane1 {
#NotNull
private String username;
#NotNull
private String password;
#NotNull
private String url;
public void setUsername(String username) {
this.username = username;
}
public void setPassword(String password) {
this.password = password;
}
public void setUrl(String url) {
this.url = url;
}
//#Primary
#Bean
DataSource dataSourceLane1() throws SQLException {
HikariDataSource dataSource = new HikariDataSource();
dataSource.setUsername(username);
dataSource.setPassword(password);
dataSource.setJdbcUrl(url);
return dataSource;
}
//#Primary
#Bean(name = "lane1EntityManagerFactory")
public EntityManagerFactory propEntityManagerFactory() throws SQLException {
Properties properties = new Properties();
// properties.put("hibernate.hbm2ddl.auto", "update");
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setPersistenceUnitName("lane1");
em.setDataSource(dataSourceLane1());
em.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
em.setPackagesToScan("lane1");
em.setJpaProperties(properties);
em.afterPropertiesSet();
return em.getObject();
}
//#Primary
#Bean(name = "lane1TransactionManager")
public PlatformTransactionManager propTransactionManager(
#Qualifier("lane1EntityManagerFactory") EntityManagerFactory barEntityManagerFactory) {
return new JpaTransactionManager(barEntityManagerFactory);
}
}
Similarly I have datasource2 and datasource3.
My goal is to have single repository class and dynamically use different datasource based on organizationId.
NOTE : I want to reuse all SimpleJpaRepository(CrudRepository) methods too.
It would be great if someone helps me with code examples. Thank you in advance.
I have just started working in java spring framework. Am just trying to populate a simple table with columns id and a name. But am getting :
Unknown entity: org.hibernate.MappingException
I get that it is commonly encountered exception. But I couldn't fix this. You can find the The entity, dao and hibernate config am using below.
HibernateConfig.java
#Getter #Setter
#Configuration#ConfigurationProperties(prefix = "databaseConfiguration")
public class HibernateConfig {
#Value("${driverClass}")
private String driverClass;
#Value("${url}")
private String url;
#Value("username")
private String username;
#Value("password")
private String password;
#Value("${hibernateDialect}")
private String hibernateDialect;
#Value("${hbm2ddlAuto}")
private String hbm2ddlAuto;
private Integer minSize;
private Integer maxSize;
#Bean
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(driverClass);
dataSource.setUrl(url);
dataSource.setUsername(username);
dataSource.setPassword(password);
return dataSource;
}
#Bean
public Properties hibernateProperties() {
Properties properties = new Properties();
properties.put("hibernate.hbm2ddl.auto", hbm2ddlAuto);
properties.put("hibernate.dialect", hibernateDialect);
properties.put("hibernate.c3p0.min_size", minSize);
properties.put("hibernate.c3p0.max_size", maxSize);
return properties;
}
#Bean
public LocalSessionFactoryBean sessionFactory(DataSource dataSource) {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(dataSource);
sessionFactory.setHibernateProperties(hibernateProperties());
return sessionFactory;
}
#Bean
public ITestDao testDao() {
ITestDao testDao = new TestDao();
return testDao;
}
}
All the properties are being taken from the .yml file. ITestDao is the interface with abstract add() method in it.
Entity class
#Getter
#Setter
#Entity
#Table(name = "test")
public class Test {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "id", nullable = false, unique = true)
private Long id;
#Column(name = "dump", nullable = false)
private String dump;
}
Dao class
#Repository
#Transactional
#Getter
#Setter
public class TestDao implements ITestDao {
#Autowired
private LocalSessionFactoryBean sessionFactoryBean;
public Test add(Test test) {
try {
sessionFactoryBean.getObject().getCurrentSession().getTransaction().begin();
sessionFactoryBean.getObject().getCurrentSession().persist(test);
} finally {
sessionFactoryBean.getObject().getCurrentSession().getTransaction().commit();
}
return test;
}
}
A service method will call this dao with #Transactional annotated above it. But while calling this add() dao method am getting Unknown entity:
org.hibernate.MappingException
Try this way :
#Bean
public LocalSessionFactoryBean sessionFactory(DataSource dataSource) {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(dataSource);
sessionFactory.setPackagesToScan(new String[] { "my.package.model" });// You need to provide to adapt : my.package.model
sessionFactory.setHibernateProperties(hibernateProperties());
return sessionFactory;
}
Good luck
You might be missing below annotation.
#EntityScan("some.known.persistence")
The #EntityScan only identifies which classes should be used by a specific persistence context.
Im trying to use Spring and JPA. I have a table in Oracle of which few of the fields are RAW(16 BYTE) type. My entity looks like following:
#Entity
#Table(name = "testTable")
public class TestTable implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#Column(name = "ID")
#Type(type = "uuid-binary")
private UUID id;
#Column(name = "TABLE_ID")
#Type(type = "uuid-binary")
private UUID tableId;
#Column(name = "STATUS")
private String status;
My repository class looks like the following:
#Repository
public interface TestRepository extends JpaRepository<TestTable, UUID> {
TestTable getTestTableByTableId(#Param("table_id") UUId table_id);
}
The column i'm trying to mark as #Param is not primary key. I have enabled JPA Repositories on configuration file with #EnableJpaRepositories as follows:
#Configuration
#EnableTransactionManagement
#EnableJpaRepositories(basePackageClasses = { TestRepository.class })
#EnableJpaAuditing
public class JpaConfig {
#Bean(name="entityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean() {
Map<String, Object> jpaProperties = new HashMap<>();
jpaProperties.put("eclipselink.weaving", "false");
jpaProperties.put("eclipselink.logging.parameters", "true");
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
entityManagerFactoryBean.setDataSource(this.getDataSource());
entityManagerFactoryBean.setPackagesToScan("com.test.entity");
entityManagerFactoryBean.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver());
entityManagerFactoryBean.setJpaVendorAdapter(this.vendorAdapter());
entityManagerFactoryBean.setJpaPropertyMap(jpaProperties);
return entityManagerFactoryBean;
}
#Bean
public JpaVendorAdapter vendorAdapter() {
EclipseLinkJpaVendorAdapter vendorAdapter = new EclipseLinkJpaVendorAdapter();
vendorAdapter.setDatabase(Database.ORACLE);
vendorAdapter.setShowSql(true);
return vendorAdapter;
}
#Bean
public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
return new PersistenceExceptionTranslationPostProcessor();
}
#Bean
public DriverManagerDataSource getDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
//datasource properties here
return dataSource;
}
#Bean()
public PlatformTransactionManager transactionManager() {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(this.entityManagerFactoryBean().getObject());
return transactionManager;
}
when i autowire the repository in my controller and invoke the method defined in the repository, JPA creates SQL in the background and tried to bind the parameter, but it is binding an object reference instead of UUID as follows:
[EL Fine]: sql: 2016-08-10 09:17:22.306--ServerSession(1292029763)--Connection(678757862)--SELECT ID, TABLE_ID, STATUS FROM TESTTABLE WHERE (TABLE_ID= ?)
bind => [[B#2f6964a4]
My question is why is it binding it as an object? and how would I resolve it? thanks in advance.
My project structure looks like
persistence/pom.xml
src/main/java/
ApplicationConfig
NetworkRepository
NetworkRepositoryImpl
Network
src/main/test/NetworkRepositoryTest
My ApplicationConfig looks like
#Configuration
#ComponentScan
#EnableJpaRepositories
public class ApplicationConfig {
#Bean
public DataSource dataSource() {
final EmbeddedDatabaseBuilder embeddedDatabaseBuilder = new EmbeddedDatabaseBuilder();
embeddedDatabaseBuilder.setType(EmbeddedDatabaseType.H2);
return embeddedDatabaseBuilder.build();
}
#Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
final HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
jpaVendorAdapter.setDatabase(Database.H2);
jpaVendorAdapter.setGenerateDdl(true);
final LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
localContainerEntityManagerFactoryBean.setJpaVendorAdapter(jpaVendorAdapter);
localContainerEntityManagerFactoryBean.setPackagesToScan(getClass().getPackage().getName());
localContainerEntityManagerFactoryBean.setDataSource(dataSource());
localContainerEntityManagerFactoryBean.setPersistenceUnitName("test-comma-pu");
return localContainerEntityManagerFactoryBean;
}
#Bean
public PlatformTransactionManager transactionManager() {
final JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
return transactionManager;
}
}
my Network entity looks like
import javax.annotation.Nonnull;
import javax.persistence.Entity;
import org.joda.time.DateTime;
#Entity
public class Network extends AbstractEntity {
private final long networkId;
private final String name;
private final boolean active;
private final DateTime createdAt;
private String createdBy;
private DateTime updatedAt;
private String updatedBy;
...
}
My NetworkRepository looks like
import java.util.List;
import javax.annotation.Nonnull;
import org.springframework.data.repository.Repository;
import com.org.comma.persistence.entities.Network;
public interface NetworkRepository extends Repository<Network, Long> {
#Nonnull
List<Network> findAll();
#Nonnull
Network save(#Nonnull final Network network);
}
My NetworkRepositoryImpl looks like
#Repository
#Transactional
public class NetworkRepositoryImpl implements NetworkRepository {
#PersistenceContext
private EntityManager entityManager;
#Override
#Nonnull
public List<Network> findAll() {
return Collections.emptyList();
}
#Nonnull
#Override
public Network save(#Nonnull final Network network) {
if (network.getId() == null) {
entityManager.persist(network);
return network;
} else {
return entityManager.merge(network);
}
}
}
and my Test looks like
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(classes = {ApplicationConfig.class, NetworkRepositoryImpl.class})
#Transactional
public class NetworkRepositoryTest {
#Autowired
NetworkRepository networkRepository;
#Test
public void testAllNetworks() {
Network network = new Network(1, "US", true, DateTime.now());
network = networkRepository.save(network);
final List<Network> networks = networkRepository.findAll();
assertTrue(networks.isEmpty());
}
}
When I run test, I see error as
java.lang.IllegalArgumentException: Unknown entity: com.org.comma.persistence.entities.Network
I found people recommending to have persistence.xml, My question is when I am already using Java Based Configuration(ApplicationConfig) and also set the base packages to scan
localContainerEntityManagerFactoryBean.setPackagesToScan(getClass().getPackage().getName());
even in that case I need persistence.xml?
The problem was
localContainerEntityManagerFactoryBean.setPackagesToScan(getClass().getPackage().getName());
getClass().getPackage().getName() resolved to com.org.comma.persistence.config but all the entities were in com.org.comma.persistence
Doing the following
localContainerEntityManagerFactoryBean.setPackagesToScan("com.yahoo.comma.persistence");
helped me fix the issue and get rid of persistence.xml