Can't made changes on synonym using spring - spring

I created a synonym called CLASSE_SYN with oracle.
Using Spring, I do like that:
#Entity
#Table(name = "CLASSE_SYN")
public class Classe implements Serializable {}
and I add on persistence.xml:
<property name="hibernate.synonyms" value="true"/>
But I can't made changes on that synonym from spring code source.
Have you please any idea about solving that issue ?.

Try upgrade your hibernate version.
Hibernate 4.3.0 supports your need.
HTH.

Related

JPA ddl-auto=create/update with schema= mentioned in Entity not working with spring boot 2.1

I have a spring boot application, with following User entity class:
#Entity
#Table(name="user")
public class User {
...
and I'm using ddl-auto=update (or create) to auto-generate the schema in the database. The database used is H2 (also tried with HSQL).
Now all works well (the required table is automatically generated when application is launched), until the entity class is changed to the following (added schema=):
#Entity
#Table(name="user", schema="myschm")
public class User {
...
Now it gives the error when creating the table: Schema "MYSCHM" not found. It seems JPA is expecting the schema MYSCHM to be present and not creating it automatically.
I started observing this issue after using Spring Boot 2.1.5. This used to work when I was using Spring Boot 1.5.3.
Is there any change made in Spring Boot 2+ that affects this? Is there any configuration change I need to do to make this work?
Thanks
The schema is not auto created by H2.
You have to add:
jdbc:h2:mem:test;INIT=CREATE SCHEMA IF NOT EXISTS MYSCHM

Spring Boot JPA CrudRepository

I'm working with Spring Boot + Spring Data JPA and facing this problem when trying to inject a class that extends CrudRepository:
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'topicRepository': Could not resolve
matching constructor (hint: specify index/type/name arguments for
simple parameters to avoid type ambiguities)
Repository Class:
public interface TopicRepository extends CrudRepository<Topic, Integer> {}
Service Class:
#Service
public class TopicService {
#Autowired
private TopicRepository topicRepository;
}
Any suggestions?
I was having the same issue, and I fixed it by switching Spring Boot versions. Changing the Spring Data JPA versions did nothing (this is where I assumed the bug would be), so I think there is a bug in Spring Boot version 1.5.1. I switched back to version 1.4.3 and the error was gone. I didn't try subsequent/different versions, so you may just have to experiment with your dependencies and their versions.
For the record, you can have your service class annotated with #Repository, it shouldn't make any difference. I've been setting these apps up the same way using the service/dao pattern, and it has never been too picky with the annotations. Hopefully this may help others whose Spring Boot development flow suddenly throws an error!
Which versions of spring-data-commons and spring-data-jpa are you using. I just ran into this using spring-data-commons 1.13.x with spring-data-jpa 1.10.x. Upgrading spring-data-jpa to 1.11.x fixed the issue for me.
I too had the same issue after updating Spring Boot to 1.5.4.
I am also using spring-data-envers, which was at version 1.0.4. Upgrading to 1.4.1 solved the problem.
I hope it helps someone :)
Make sure:
1) TopicRepository is annotated with #Repository.
2) You have the scanning packages configured:
<jpa:repositories base-package="mypkg.repositories"></jpa:repositories>
Had the same issue on 1.5.2. Upgrading to 1.5.5 solved the problem.
You can use Applicationcontext to inject repository to this reference topicRepository..
You just declare applicationcontext in #rest controller class
Same like topicRepository by using annotation. Then you pass this to the service class which should take parms through constructor.
Ex-
public TopicService(Applicationcontext ctx) {this.topicRepository =context.getBean(TopicRepository.class);
}

spring data for mongo Caused by: java.lang.AbstractMethodError

i use spring data to jpa and mongo.
dependency:
spring version is 4.0.2.RELEASE
spring-data-jpa version is 1.4.3.RELEASE
spring-data-mongodb version is 1.2.0.RELEASE
xml config:
<context:component-scan base-package="develop" />
<jpa:repositories base-package="develop.erp"
entity-manager-factory-ref="entityManagerFactory"
transaction-manager-ref="transactionManager" />
<mongo:repositories base-package="develop.doc" />
model:
#Document
public class OrderItem extends AbstractDocument {
enter code here
#Id
private BigInteger id;
private Integer orderNumber;
public get and set method ...
}
public interface IOrderItemDao extends PagingAndSortingRepository<OrderItem, BigInteger> {
List<OrderItem> findByOrderNumber(Integer number);
}
exception :
Caused by: java.lang.AbstractMethodError
at org.springframework.data.repository.query.Parameters.getBindableParameters(Parameters.java:235)
at org.springframework.data.repository.query.Parameters.assertEitherAllParamAnnotatedOrNone(Parameters.java:262)
at org.springframework.data.repository.query.Parameters.<init>(Parameters.java:85)
at org.springframework.data.mongodb.repository.query.MongoParameters.<init>(MongoParameters.java:47)
at org.springframework.data.mongodb.repository.query.MongoQueryMethod.createParameters(MongoQueryMethod.java:76)
at org.springframework.data.repository.query.QueryMethod.<init>(QueryMethod.java:70)
at org.springframework.data.mongodb.repository.query.MongoQueryMethod.<init>(MongoQueryMethod.java:62)
at org.springframework.data.mongodb.repository.support.MongoRepositoryFactory$MongoQueryLookupStrategy.resolveQuery(MongoRepositoryFactory.java:119)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:304)
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:161)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:162)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:44)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:144)
can someone have any idea ?
thanks very much..
In my case I had spring-data-solr(2.0.1) and spring-data-jpa(1.9.1) in my project. I noticed SolrQueryLookupStrategy was implementing QueryLookupStrategy interface from spring-data-commons which was transitively taken from spring-data-jpa jar. The problem was new solr was not compatible with old spring-data-jpa - signature of method in QueryLookupStrategy changed and code was not compiled correctly. Bumping spring-data-jpa to 1.10.1 solved the issue. I assume you have a similar problem. Track down where exception is thrown and search for compilation problems in spring jars.
This is due to incompatible version of spring-data and db-driver dependency. Please check if the version of db-driver is compatible with the provided spring-data dependency. I was facing the same issue, resolved by bumping the version of 'spring-data'.

Flyway and spring integration

How do I properly configure flyway when integrating with Spring? I see there is a configure method that takes properties, but from the spring XML it would take a setter method to provide a way to inject a Properties instance.
I could write my own Pojo to delegate the configuration to the flyway instance, but it somehow feels like I have missed something.
Here is my configuration:
<bean
id="flyway"
class="com.googlecode.flyway.core.Flyway"
init-method="migrate"
lazy-init="false"
depends-on="dataSource"
>
<property name="dataSource" ref="dataSource" />
<property name="locations" value="classpath:/META-INF/migrations" />
</bean>
I would like to provide a dedicated property file for the migration configuration as documented here:
https://github.com/flyway/flyway/blob/master/flyway-commandline/src/main/assembly/flyway.properties
From the javadoc I see that I can set most of the properties. I could work with spring ${} property replacements and loading the property file with the built in mechs, but this would make those properties available to all beans, and I would add each one I need.
My wrapper would provide a setter so I could add the following to my spring xml config:
<property name="configLocations" value="classpath:/META-INF/flyway.properties" />
Any thoughts appreciated.
Spring's MethodInvokingFactoryBean should do what you want.
Alternatively, you can create a migration based on JdbcTemplate using Flyway's SpringJdbcMigration. The following example is copied from the Flyway documentation:
import com.googlecode.flyway.core.api.migration.spring.SpringJdbcMigration;
import org.springframework.jdbc.core.JdbcTemplate;
public class V1_2__Another_user implements SpringJdbcMigration {
#Override
public void migrate(JdbcTemplate jdbcTemplate) throws Exception {
jdbcTemplate.execute("INSERT INTO test_user (name) VALUES ('Obelix')");
}
}
You should use spring annotation and wrap Flyway class, and do whatever you want. For instance, configuring flyway properties. This blog post may give you an example how to do http://esofthead.com/migrate-database-highly-change-environment-multiple-versions-management/

Spring+JPA #Transactional not committing

I understand the similar question have been asked before here, but I couldn't find the solution to my problem. Basically, I am trying to use JPA through Hibernate in Spring, but the data is not being persisted for some reason.Turning on debug on spring transaction reveals nothing - EntityManager open and closed, but nothing shows up as far as transaction manager concerns ... I am sure I miss something big, any help is appreciated! see the following for more details.
TIA
Oliver
The basic layout is as follows: class FooDaoJPA’s save function calls out entityManager.persist(object) to persist the object.
class FooServiceImpl implements the service interface by:
#Transactional(rollbackFor = DataAccessException.class,
readOnly = false, timeout = 30,
propagation = Propagation.SUPPORTS,
isolation = Isolation.DEFAULT)
public void saveFoo(Foo foo) throws DataAccessException {
fooDao.save(foo);
}
Noted that fooDao is injected by Spring IoC
Finally controller is injected a FooService and call saveFoo() to persist data.
JPA configuration
<!-- JPA Entity Manager Factory -->
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:dataSource-ref="feDataSource"/>
<!-- Transaction Config -->
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="entityManagerFactory"/>
<tx:annotation-driven mode="aspectj"
transaction-manager="transactionManager"/>
Note the mode="aspectj" in your configuration. It requires additional configuration and usually you shouldn't use it unless you understand what does it mean and why do you need it. See 10.5.6 Using #Transactional.
The first thing that looks like a potential issue is your setting for propagation. Here is documentation showing the values you can specify:
http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/transaction/annotation/Propagation.html
Note that you've specified SUPPORTS which "Support a current transaction, execute non-transactionally if none exists". You probably want REQUIRED, which is the default, and will either use an existing transaction or create one if one does not currently exist.
In my case:
Using JPA with Spring MVC - all of my tests and code ran fine without error - symptom was that commits would simply not save to the database no matter what I tried.
I had to add
to my applicationContext.xml and cglib-nodep-2.1_3.jar aopalliance-1.0.jar
Definitely the fix in my case. Without annotation-driven Spring will not scan for the #Transactional annotation

Resources