这里的Spring文档http://docs.spring.io/spring-data/data-jpa/docs/current/reference/html/repositories.html#repositories.custom-implementations提供了向所有存储库或者a添加自定义功能的示例单个存储库,而不是两者.
假设我想向所有存储库添加一些自定义函数(使用自定义存储库工厂Bean),而另一些只添加到单个存储库(文档说使用自定义接口和自定义Impl); 我该怎么做到这一点?
一些示例代码,我将"setCurrentTenansInSession"方法添加到所有存储库; 现在我想将一个自定义方法(例如"newCustomMethod")添加到单个存储库(这是一个MyJpaRepository,就像我的自定义存储库工厂一样).我该怎么做呢?
自定义行为界面:
@NoRepositoryBean
public interface MyJpaRepository<T, ID extends Serializable> extends JpaRepository<T, ID> {
public void setCurrentTenantInSession(Object object);
}
Run Code Online (Sandbox Code Playgroud)
自定义行为实现:
public class MultiTenantSimpleJpaRepository<T, ID extends Serializable> extends SimpleJpaRepository<T, ID> implements MyJpaRepository<T, ID> {
public void setCurrentTenantInSession(Object object) {
//custom impl
}
}
Run Code Online (Sandbox Code Playgroud)
自定义存储库工厂bean:
public class MultiTenantJpaRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extends Serializable> extends JpaRepositoryFactoryBean<T, S, ID> {
@Override
protected RepositoryFactorySupport createRepositoryFactory(EntityManager entityManager) {
return new MultiTenantJpaRepositoryFactory(entityManager);
}
}
Run Code Online (Sandbox Code Playgroud)
最后是自定义存储库工厂:
public class MultiTenantJpaRepositoryFactory extends JpaRepositoryFactory …Run Code Online (Sandbox Code Playgroud) 在Spring JPA + Hibernate环境中,我需要启用Hibernate实体过滤器.所以我应该有权访问Hibernate Session对象,但我正在使用EntityManagerFactory和Spring JPA魔法.有任何Session拦截器,所以每次Spring创建一个新Session时我都可以调用enableFilters()方法吗?
我想在使用Hibernate时看到我的SQL查询的实际参数.我将其添加到我的logback.xml中以查看查询(带有问号):
<logger name="org.hibernate.type" level="TRACE" />
Run Code Online (Sandbox Code Playgroud)
但没有效果.
是否需要特殊配置?
OnConsoleStatusListener向我显示正确的配置
23:48:15,246 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.hibernate.type] to TRACE
Run Code Online (Sandbox Code Playgroud)
但没有来自org.hibernate.type包的输出.
我正在使用Spring和Jpa.
在从数据源读取实体后,为标记为@Transient的字段设置值的最佳解决方案是什么?
我正在使用EclipseLink,我正在使用他的postBuild事件解决方案尝试DescriptorEventAdapter,因为我还需要使用Spring bean获取默认值(显然使用DI),但我知道是否有任何更简单的解决方案我是失踪.
提前致谢
我正在尝试基于多个xml模式为Spring WS Web服务动态生成WSDL。我有多个xsd文件,所有文件都使用xsd:import元素“连接”。
Spring WS参考说:
如果要使用包含或导入的多个模式,则需要将Commons XMLSchema放在类路径上。如果Commons XMLSchema位于类路径上,则上述元素将跟随所有XSD导入和包含,并将它们作为单个XSD内联到WSDL中。这极大地简化了架构的部署,仍然使分别编辑它们成为可能。
所以我添加了这个Maven依赖项:
<dependency>
<groupId>org.apache.ws.xmlschema</groupId>
<artifactId>xmlschema-core</artifactId>
<version>2.2.1</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
并以这种方式配置WSDL构建器:
@Bean(name="updateContactService")
public DefaultWsdl11Definition defaultWsdl11Definition() throws Exception {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setPortTypeName("updateContactPort");
wsdl11Definition.setLocationUri("/ws/updateContact");
wsdl11Definition.setTargetNamespace("http://spring.io/guides/gs-producing-web-service");
wsdl11Definition.setSchema(updateContactXsd());
return wsdl11Definition;
}
@Bean
public XsdSchemaCollection updateContactXsd() throws Exception {
return new SimpleXsdSchema(new ClassPathResource("xsds/contact/outboundMessage.xsd"));
}
Run Code Online (Sandbox Code Playgroud)
但是生成的WSDL仅包含一个架构元素(并以错误的位置显示了导入)。
<xs:import namespace="http://xmlns.oracle.com/apps/cdm/foundation/parties/personService/" schemaLocation="personService.xsd"/>
Run Code Online (Sandbox Code Playgroud)
有小费吗?Spring WS版本是2.3.1
<?xml version="1.0" encoding="UTF-8" standalone="no"?><wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:sch="http://xmlns.oracle.com/apps/crmCommon/content/outboundMessage/types/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://spring.io/guides/gs-producing-web-service" targetNamespace="http://spring.io/guides/gs-producing-web-service">
<wsdl:types>
<xs:schema xmlns="http://xmlns.oracle.com/apps/crmCommon/content/outboundMessage/types/" xmlns:ns2="http://xmlns.oracle.com/apps/cdm/foundation/parties/personService/" xmlns:tns0="http://xmlns.oracle.com/apps/crmCommon/content/outboundMessage/types/" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://xmlns.oracle.com/apps/crmCommon/content/outboundMessage/types/">
<xs:import namespace="http://xmlns.oracle.com/apps/cdm/foundation/parties/personService/" schemaLocation="personService.xsd"/>
<xs:element name="process" type="tns0:processType"/>
<xs:complexType name="processType">
<xs:sequence>
<xs:element maxOccurs="unbounded" …Run Code Online (Sandbox Code Playgroud) spring ×5
hibernate ×2
jpa ×2
spring-data ×2
eclipselink ×1
java ×1
logback ×1
spring-orm ×1
spring-ws ×1
transient ×1
wsdl ×1
xsd ×1