小编dan*_*ter的帖子

处理事务中的spring-data-rest应用程序事件

我需要在更新数据时通过JMS向外部系统发布通知事件.我想这样做是在同一个事务中完成的,因为对象被提交到数据库以确保完整性.

Spring-data-rest发出的ApplicationLifecycle事件似乎是实现此逻辑的逻辑位置.

@org.springframework.transaction.annotation.Transactional
public class TestEventListener extends AbstractRepositoryEventListener<Object> {

    private static final Logger LOG = LoggerFactory.getLogger(TestEventListener.class);

    @Override
    protected void onBeforeCreate(Object entity) {
        LOG.info("XXX before create");
    }

    @Override
    protected void onBeforeSave(Object entity) {
        LOG.info("XXX before save");
    }

    @Override
    protected void onAfterCreate(Object entity) {
        LOG.info("XXX after create");
    }

    @Override
    protected void onAfterSave(Object entity) {
        LOG.info("XXX after save");
    }

}
Run Code Online (Sandbox Code Playgroud)

但是,这些事件发生在tx开始和提交之前和之后.

08 15:32:37.119 [http-nio-9000-exec-1] INFO  n.c.v.vcidb.TestEventListener - XXX before create 
08 15:32:37.135 [http-nio-9000-exec-1] TRACE o.s.t.i.TransactionInterceptor - Getting transaction for [org.springframework.data.jpa.repository.support.SimpleJpaRepository.save]



08 15:32:37.432 [http-nio-9000-exec-1] …
Run Code Online (Sandbox Code Playgroud)

spring-transactions spring-data-jpa spring-data-rest

14
推荐指数
1
解决办法
4007
查看次数

如何在jpa本机查询中转换joda DateTime

我有一个实体,其中DateTime属性与hibernate持久存在

@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
@Column(name = "EFF_DT")
protected DateTime effDt;
Run Code Online (Sandbox Code Playgroud)

这一切都适用于常规spring-data-jpa生成的查询.

我正在尝试添加自定义本机查询

 @Query(value = "SELECT COUNT(*) FROM wsa_circuit_state_history ch WHERE ch.eff_dt between ?1 and ?2", nativeQuery = true)
    Integer countEffDateBetween(DateTime start, DateTime end);
Run Code Online (Sandbox Code Playgroud)

我得到的错误是当试图调用它时

 java.sql.SQLException: ORA-00932: inconsistent datatypes: expected DATE got BINARY
Run Code Online (Sandbox Code Playgroud)

这是我在将自定义类型映射添加到我的实体之前使用常规spring-data finders时遇到的相同错误

 @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
Run Code Online (Sandbox Code Playgroud)

我如何使spring-data-jpa/hibernate使用自定义类型映射参数到本机查询?

hibernate jpa jodatime spring-data-jpa

7
推荐指数
1
解决办法
4172
查看次数

使用 jaxb2 基础生成 toString 方法时,如何使用绑定文件排除字段

旧站点上有一些文档, 但不清楚在使用绑定文件时如何应用配置。

这是我用来向生成的 JAXB 对象添加 toString、equals 等的 Maven 配置。

  <plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>0.12.3</version>
    <executions>
      <execution>
        <goals>
          <goal>generate</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <schemaIncludes>
        <include>*.xsd</include>
      </schemaIncludes>
      <args>
        <arg>-Xfluent-api</arg>
        <arg>-XautoNameResolution</arg>
        <arg>-XtoString</arg>
        <arg>-Xequals</arg>
        <arg>-XhashCode</arg>
        <arg>-Xcopyable</arg>
      </args>
      <plugins>
        <plugin>
          <groupId>org.jvnet.jaxb2_commons</groupId>
          <artifactId>jaxb2-fluent-api</artifactId>
          <version>3.0</version>
        </plugin>
        <plugin>
            <groupId>org.jvnet.jaxb2_commons</groupId>
            <artifactId>jaxb2-basics</artifactId>
            <version>0.9.4</version>
        </plugin>
      </plugins>
    </configuration>
  </plugin>
Run Code Online (Sandbox Code Playgroud)

java jaxb maven-jaxb2-plugin jaxb2-basics

1
推荐指数
1
解决办法
1399
查看次数