How to register a hibernate typedescriptor in a "classic" Spring 5 application with jpa entitymanager - spring

I have a classic spring 5 application (NO spring boot). For a custom basic type i have created a typedescriptor by subclassing AbstractTypeDescriptor according to Hibernate 5.2 Documentation - 2.3.5. Explicit BasicTypes. I am using hibernate via an jpa entitymanager. I have two spring beans configured for that: a LocalContainerEntityManagerFactoryBean and a HibernateJpaVendorAdapter.
Now i am a bit lost, how to register the typedescriptor during startup of the application. The docs mention an approach using a hibernate configuration object. But i have no idea, how to get this? Any help appreciated!

Related

What is the Bean Scope of Hibernate Persistence Context? Singleton or Request? and how to implement Unit of Work with Hibernate?

I am coming from the .NetCore Background and learning Hibernate now for a new Project.
Previously I have worked with Entity Framework Core (EF Core) and Hibernate looks quite similar too.
I have some questions though:
In .NetCore, one could mark make EF Core DbContext either as a Transient (Prototype in Spring) or Scoped (Request in Spring).
What is the default Bean Scope for the Hibernate Session or Persistence Context? and how do I change it to Request Scope?

How to access datasource information in spring boot with spring data jpa and hibernate

I need to perform an health check on my application that uses spring boot with spring data jpa and hibernate.
I need to do this with jpa and not make specific to any implementation.
In EclipseLink we can use EntityManagerFactoryDelegate as shown below, but I dont know How to do this with spring data jpa and hibernate.
EntityManagerFactoryDelegate delegate = entityManager.getEntityManagerFactory().unwrap(EntityManagerFactoryDelegate.class);
PersistenceInfo = delegate.getSetupImpl().getPersistenceUnitInfo();
DataSourceImpl dataSource = (DataSource) info.getNpnJtaDataSource();
return dataSource.getName();
Can anyone suggest me how to do this in spring data jpa using hibernate.
You can use spring boot actuator dependency for healthcheck doesn't need to configure externally. Once you define Datasource Bean it will auto pick database healthcheck.
if you want to enable/disable database health check you can use the below property,
management.health.db.enabled=<boolean, true || false>
implementation reference :https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html

circular dependency error for dataSource after adding spring DATA JPA

I am working in spring boot security with Oauth2. Oauth2 to makes use of jdbcAuthentication in AuthorizationServerConfigurerImpl. But in my webSecurityCofigurer implementing class i want to use Spring data JPA to implement userDetailsService. After enabling #EnableJpaRepositories it is throwing circular depenency error and not able to load dataSource which i am defining in AuthorizationServerConfigurerImpl.
Please help me resolving issue

How do I change my configuration to a different data source?

I went through the Data Access With Spring tutorial and the in memory database they use in step 3 is working. But, I'm not clear on what I need to add/change to get it to query my development (Oracle) database now?
I want to use Hibernate, do I still need this JPAConfiguration class or would I have something Hibernate specific?
Please don't just post a link to the Hibernate reference. I'm reviewing that as well, but since I'm also using Spring, it's not clear to me the proper way to load the hibernate.cfg.xml and inject the Hibernate session in that context.
Don't be blocked by the fact that the class is called JPAConfiguration. You need to understand what the class does. Note that it has the annotation #Configuration which you can use along with AnnotationConfigApplicationContext to produce a Spring bean context.
That functionality is described in the Spring documentation for The IoC container.
What you need to change is how your DataSource and EntityManagerFactory beans are created. You'll need to use a DataSource that gets Connection instances from a JDBC Driver that supports Oracle databases.

Transaction in Spring with datasources create in runtime

I have a problem with transaction in spring, because in my project datasources are created in runtime from side files and according to documentation:
I should inject to TransactionManager dataSource and made it visible for annotation #Transactional using <tx:annotation-driven transaction-manager="txManager"/>.
So my question is how can I do it when I want to use annotation?
First of all how are you creating the datasources at runtime.
if directly as Datasource=new datasource... I will suges use BeanDefinitionBuilder in Spring 3.2 to Create the Datasourcebean and then register it via BeanDefinitionRegistry.
and then get the bean from Spring context and it will be considered using the transaction.

Resources