Hibernate看不到已插入sql脚本数据

时间:2019-02-20 00:31:22

标签: hibernate spring-boot flyway

该项目在Spring Boot(v。2.0.5),Hibernate(v。5.2.17),Ehcache,Flyway,Solr上工作。 我有一个ConceptEntity:

@Entity
@Table(name = "concept", schema = "common")
public class ConceptEntity extends AbstractAuditableEntity {
    private long id;
    private Long organizationId;
    private String comment;
    private String systemName;
    private Long conceptTypeId;
    private ConceptTypeEntity conceptType;

    List<ConceptTermEntity> conceptTerm;
    List<ConceptDefinitionEntity> conceptDefinition;
    List<ConceptAbbreviationEntity> conceptAbbreviation;

    @Id
    @Column
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq")
    @SequenceGenerator( name="seq", sequenceName="common.common_generic_seq", allocationSize=1 )
    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    @Basic
    @Column(name = "organization_id")
    public Long getOrganizationId() {
        return organizationId;
    }
    ...
}

我的存储库组件:

@Slf4j
@Component
@Transactional
public class OntologyDAOImpl implements OntologyDAO {

    @PersistenceContext
    EntityManager em;
    ...
    @Override
    public ConceptEntity findConceptByTypeAndSystemName(String conceptTypeSettings, String category) {
        return em.createNamedQuery(ConceptEntity.FIND_BY_TYPE_NAME_AND_NAME, ConceptEntity.class)
            .setParameter("conceptTypeSystemName", conceptTypeSettings)
            .setParameter("systemName", category)
            .getSingleResult();//NoResultException
    }
    ...
}

和persistence.xml:

<hibernate-configuration>
  <session-factory>
    <property name="connection.url">jdbc:postgresql://localhost:5432/MDM_ADMIN</property>
    <property name="connection.driver_class">org.postgresql.Driver</property>
    <property name="connection.isolation">1</property>
    <property name="current_session_context_class">thread</property>
    <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider"</property>
    <property name="cache.use_second_level_cache">false</property>
    <property name="cache.use_query_cache">false</property>
    <property name="show_sql">true</property>
    <property name="connection.autocommit">true</property>
      <mapping class="mdm.ontology.entity.ConceptEntity"/>
      <mapping class="rcg.mdm.admin.entity.EmailEntity"/>
      ...
  </session-factory>
</hibernate-configuration>

我使用帮助SQL编辑器在common.concept中插入了2行。 然后我启动了应用程序,看到什么EntityManager找不到这些行。

SELECT MAX(id) FROM common.concept = 103696
em.find(ConceptEntity.class, 103696l) = null (<=103694 hibernate returns)

我的application.yml:

...
spring:
  cache.jcache:
      config: classpath:ehcache3.xml


  jpa.properties.hibernate.jdbc:
    lob.non_contextual_creation: true
    naming.physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

  datasource:
  ...

我应该怎么做才能使Hibernate重新获得在SQL脚本中创建的条目?我的项目中没有@Cache。

0 个答案:

没有答案