org.hibernate.criterion.Restrictions.naturalId()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(100)

本文整理了Java中org.hibernate.criterion.Restrictions.naturalId方法的一些代码示例,展示了Restrictions.naturalId的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Restrictions.naturalId方法的具体详情如下:
包路径:org.hibernate.criterion.Restrictions
类名称:Restrictions
方法名:naturalId

Restrictions.naturalId介绍

[英]Consider using any of the natural id based loading stuff from session instead, especially in cases where the restriction is the full set of natural id values.
[中]考虑从会话中使用任何基于自然ID的加载项,特别是在限制为完整的自然ID值集的情况下。

代码示例

代码示例来源:origin: hibernate/hibernate-orm

private Criteria getCriteria(Session s) {
  Criteria crit = s.createCriteria( A.class, "anAlias" );
  crit.add( Restrictions.naturalId().set( "name", "name1" ) );
  crit.setFlushMode( FlushMode.COMMIT );
  crit.setCacheable( true );
  return crit;
}

代码示例来源:origin: hibernate/hibernate-orm

@TestForIssue(jiraKey = "HHH-9333")
@Test
public void testNaturalIdCriteria() {
  Session s = openSession();
  s.beginTransaction();
  A u = new A(new AId(1), "testCode" );
  s.persist( u );
  s.getTransaction().commit();
  s.close();
  s = openSession();
  s.beginTransaction();
  u = ( A ) s.createCriteria( A.class )
      .add( Restrictions.naturalId().set( "shortCode", "testCode" ) )
      .uniqueResult();
  assertNotNull( u );
  s.getTransaction().commit();
  s.close();
  s = openSession();
  s.beginTransaction();
  s.createQuery( "delete A" ).executeUpdate();
  s.getTransaction().commit();
  s.close();
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testNaturalIdCriteria() {
  Session s = openSession();
  s.beginTransaction();
  Account u = new Account(new AccountId(1), "testAcct" );
  s.persist( u );
  s.getTransaction().commit();
  s.close();
  s = openSession();
  s.beginTransaction();
  u = ( Account ) s.createCriteria( Account.class )
      .add( Restrictions.naturalId().set( "shortCode", "testAcct" ) )
      .setCacheable( true )
      .uniqueResult();
  assertNotNull( u );
  s.getTransaction().commit();
  s.close();
  s = openSession();
  s.beginTransaction();
  s.createQuery( "delete Account" ).executeUpdate();
  s.getTransaction().commit();
  s.close();
}

代码示例来源:origin: hibernate/hibernate-orm

s.beginTransaction();
u = ( User ) s.createCriteria( User.class )
    .add( Restrictions.naturalId().set( "userName", "steve" ) )
    .setCacheable( true )
    .uniqueResult();
s.beginTransaction();
u = ( User ) s.createCriteria( User.class )
    .add( Restrictions.naturalId().set( "userName", "steve" ) )
    .setCacheable( true )
    .uniqueResult();
s.beginTransaction();
u = ( User ) s.createCriteria( User.class )
    .add( Restrictions.naturalId().set( "userName", "steve" ) )
    .setCacheable( true )
    .uniqueResult();

代码示例来源:origin: hibernate/hibernate-orm

s.beginTransaction();
u = ( User ) s.createCriteria( User.class )
    .add( Restrictions.naturalId().set( "userName", "steve" ) )
    .setCacheable( true )
    .uniqueResult();
s.beginTransaction();
u = ( User ) s.createCriteria( User.class )
    .add( Restrictions.naturalId().set( "userName", "steve" ) )
    .setCacheable( true )
    .uniqueResult();
s.beginTransaction();
u = ( User ) s.createCriteria( User.class )
    .add( Restrictions.naturalId().set( "userName", "steve" ) )
    .setCacheable( true )
    .uniqueResult();

代码示例来源:origin: hibernate/hibernate-orm

s.beginTransaction();
u = ( User ) s.createCriteria( User.class )
    .add( Restrictions.naturalId().set( "userName", "steve" ) )
    .setCacheable( true )
    .uniqueResult();
s.beginTransaction();
u = ( User ) s.createCriteria( User.class )
    .add( Restrictions.naturalId().set( "userName", "steve" ) )
    .setCacheable( true )
    .uniqueResult();

代码示例来源:origin: hibernate/hibernate-orm

s.beginTransaction();
u = ( User ) s.createCriteria( User.class )
    .add( Restrictions.naturalId().set( "userName", "steve" ) )
    .setCacheable( true )
    .uniqueResult();
s.beginTransaction();
u = ( User ) s.createCriteria( User.class )
    .add( Restrictions.naturalId().set( "userName", "steve" ) )
    .setCacheable( true )
    .uniqueResult();
assertEquals( 0, sessionFactory().getStatistics().getNaturalIdCacheHitCount() );//0: no stats since hbm.xml can't enable NaturalId caching
u = ( User ) s.createCriteria( User.class )
    .add( Restrictions.naturalId().set( "userName", "steve" ) )
    .setCacheable( true )
    .uniqueResult();

代码示例来源:origin: hibernate/hibernate-orm

s.beginTransaction();
u = ( User ) s.createCriteria( User.class )
    .add( Restrictions.naturalId().set( "userName", "steve" ) )
    .setCacheable( true )
    .uniqueResult();
s.beginTransaction();
u = ( User ) s.createCriteria( User.class )
    .add( Restrictions.naturalId().set( "userName", "steve" ) )
    .setCacheable( true )
    .uniqueResult();

代码示例来源:origin: hibernate/hibernate-orm

s.beginTransaction();
u = ( User ) s.createCriteria( User.class )
    .add( Restrictions.naturalId().set( "userName", "steve" ) )
    .setCacheable( true )
    .uniqueResult();
s.beginTransaction();
u = ( User ) s.createCriteria( User.class )
    .add( Restrictions.naturalId().set( "userName", "steve" ) )
    .setCacheable( true )
    .uniqueResult();
assertEquals( 0, sessionFactory().getStatistics().getNaturalIdCacheHitCount() ); //1: no stats since hbm.xml can't enable NaturalId caching
u = ( User ) s.createCriteria( User.class )
    .add( Restrictions.naturalId().set( "userName", "steve" ) )
    .setCacheable( true )
    .uniqueResult();

代码示例来源:origin: hibernate/hibernate-orm

Criteria criteria = s.createCriteria( Citizen.class );
criteria.add(
    Restrictions.naturalId().set( "ssn", "1234" ).set(
        "state",
        france

代码示例来源:origin: hibernate/hibernate-orm

State france = this.getState( s, "Ile de France" );
Criteria criteria = s.createCriteria( Citizen.class );
criteria.add( Restrictions.naturalId().set( "ssn", "1234" ).set( "state", france ) );
criteria.setCacheable( true );

代码示例来源:origin: hibernate/hibernate-orm

tx = s.beginTransaction();
Criteria criteria = s.createCriteria( NaturalIdOnManyToOne.class );
criteria.add( Restrictions.naturalId().set( "citizen", c1 ) );
criteria.setCacheable( true );

代码示例来源:origin: riotfamily/riot

@SuppressWarnings("unchecked")
public static void removeEmptyEntries(String bundle) {
  List<MessageBundleEntry> entries = getSession().createCriteria(MessageBundleEntry.class)
    .setCacheable(true)
    .setCacheRegion("messages")
    .add(Restrictions.sizeLe("messages", 1))
    .add(Restrictions.naturalId()
      .set("bundle", bundle))
      .list();
  
  for (MessageBundleEntry entry : entries) {
    entry.delete();
  }
}

代码示例来源:origin: org.infinispan/infinispan-hibernate-cache-commons

private void getCitizenWithCriteria(SessionFactory sf) throws Exception {
  withTxSession(sf, s -> {
    State france = getState(s, "Ile de France");
    Criteria criteria = s.createCriteria( Citizen.class );
    criteria.add( Restrictions.naturalId().set( "ssn", "1234" ).set( "state", france ) );
    criteria.setCacheable( true );
    criteria.list();
  });
}

代码示例来源:origin: org.infinispan/infinispan-hibernate-cache-commons

private void deleteCitizenWithCriteria(SessionFactory sf) throws Exception {
  withTxSession(sf, s -> {
    State france = getState(s, "Ile de France");
    Criteria criteria = s.createCriteria( Citizen.class );
    criteria.add( Restrictions.naturalId().set( "ssn", "1234" ).set( "state", france ) );
    criteria.setCacheable( true );
    Citizen c = (Citizen) criteria.uniqueResult();
    s.delete(c);
  });
}

代码示例来源:origin: org.infinispan/infinispan-hibernate-cache-commons

State france = ReadWriteTest.this.getState(s, "Ile de France");
Criteria criteria = s.createCriteria( Citizen.class );
criteria.add( Restrictions.naturalId().set( "ssn", "1234" ).set( "state", france ) );
criteria.setCacheable( true );

相关文章