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

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

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

Restrictions.idEq介绍

[英]Apply an "equal" constraint to the identifier property
[中]对标识符属性应用“相等”约束

代码示例

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

@Test
public void shouldNotRetrieveSubSubSubEntityWithCriteria() {
  session = openSession();
  try {
    SubSubSubEntity loaded = (SubSubSubEntity) session.createCriteria( SubSubSubEntity.class )
        .add( Restrictions.idEq( subSubEntityId ) )
        .uniqueResult();
    assertNull( loaded );
  }
  finally {
    session.close();
  }
}

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

@Test
public void shouldRetrieveSubSubEntityWithCriteria() {
  session = openSession();
  try {
    SubSubEntity loaded = (SubSubEntity) session.createCriteria( SubSubEntity.class )
        .add( Restrictions.idEq( subSubEntityId ) )
        .uniqueResult();
    assertNotNull( loaded );
  }
  finally {
    session.close();
  }
}

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

@Test
public void testBidirAssignedId() throws Exception {
  doInHibernate( this::sessionFactory, session -> {
    PartyAffiliate affiliate = new PartyAffiliate();
    affiliate.partyId = "id";
    session.persist( affiliate );
  } );
  doInHibernate( this::sessionFactory, session -> {
    PartyAffiliate affiliate = (PartyAffiliate) session.createCriteria(
        PartyAffiliate.class )
        .add( Restrictions.idEq( "id" ) )
        .uniqueResult();
    assertNotNull( affiliate );
    assertEquals( "id", affiliate.partyId );
    assertNull( affiliate.party );
  } );
  doInHibernate( this::sessionFactory, session -> {
    PartyAffiliate affiliate = session.get(
        PartyAffiliate.class,
        "id"
    );
    assertNull( affiliate.party );
    session.delete( affiliate );
  } );
}

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

PersonAddress personAddress = (PersonAddress) session.createCriteria(
    PersonAddress.class )
    .add( Restrictions.idEq( _personAddress.getId() ) )
    .uniqueResult();
assertNotNull( personAddress );

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

c = (Contract) s.createCriteria( Contract.class ).add( Restrictions.idEq( Long.valueOf( c.getId() ) )).uniqueResult();
assertEquals( 1, c.getParties().size() );
Party party = ( Party ) c.getParties().iterator().next();
c2 = (Contract) s.createCriteria( Contract.class ).add( Restrictions.idEq( Long.valueOf( c2.getId() ) )).uniqueResult();
c2.addParty( party );
t.commit();
c = (Contract) s.createCriteria( Contract.class ).add( Restrictions.idEq( Long.valueOf( c.getId() ) )).uniqueResult();
c2 = (Contract) s.createCriteria( Contract.class ).add( Restrictions.idEq( Long.valueOf( c2.getId() ) )).uniqueResult();
if ( isContractPartiesInverse ) {
  assertEquals( 1, c.getParties().size() );

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

.add( Restrictions.idEq( "c1" ) )
    .uniqueResult();
assertTrue( child.getParent().getChildren().contains( child ) );

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

c = (Contract) s.createCriteria( Contract.class ).add( Restrictions.idEq( Long.valueOf( c.getId() ) )).uniqueResult();
c2 = (Contract) s.createCriteria( Contract.class ).add( Restrictions.idEq( Long.valueOf( c2.getId() ) )).uniqueResult();
if ( isContractPartiesInverse ) {
  assertEquals( 1, c.getParties().size() );

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

.add( Restrictions.idEq( "c1" ) )
    .uniqueResult();
assertTrue( child.getParent().getChildren().contains( child ) );
    .add( Restrictions.idEq( "c1" ) )
    .uniqueResult();
assertTrue( child.getParent().getChildren().contains( child ) );

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

@Test
public void testBidirDefaultIdGenerator() throws Exception {
  PersonAddress _personAddress = doInHibernate(
      this::sessionFactory,
      session -> {
        PersonAddress personAddress = new PersonAddress();
        personAddress.setPerson( null );
        session.persist( personAddress );
        return personAddress;
      }
  );
  doInHibernate( this::sessionFactory, session -> {
    PersonAddress personAddress = (PersonAddress) session.createCriteria(
        PersonAddress.class )
        .add( Restrictions.idEq( _personAddress.getId() ) )
        .uniqueResult();
    assertNotNull( personAddress );
    assertNull( personAddress.getPerson() );
  } );
  doInHibernate( this::sessionFactory, session -> {
    PersonAddress personAddress = session.get(
        PersonAddress.class,
        _personAddress.getId()
    );
    assertNull( personAddress.getPerson() );
    session.delete( personAddress );
  } );
}

代码示例来源:origin: magro/memcached-session-manager

@Override
public Person execute( final Session session ) {
  final Criteria crit = session.createCriteria( Person.class ).add( Restrictions.idEq( personId ) );
  @SuppressWarnings( "unchecked" )
  final List<Person> list = crit.list();
  Assert.assertEquals( list.size(), 1 );
  final Person result = list.get( 0 );
  Hibernate.initialize( result.animals );
  return result;
}

代码示例来源:origin: org.grails/grails-hibernate

@Override
public Query idEq(Object value) {
  addToCriteria(Restrictions.idEq(value));
  return this;
}

代码示例来源:origin: org.grails/grails-hibernate

@Override
public Query idEq(Object value) {
  addToCriteria(Restrictions.idEq(value));
  return this;
}

代码示例来源:origin: org.grails/grails-datastore-gorm-hibernate-core

@Override
  public org.hibernate.criterion.Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.Criterion criterion, String alias) {
    return Restrictions.idEq(((Query.IdEquals) criterion).getValue());
  }
});

代码示例来源:origin: uk.ac.ebi.intact/intact-core

public List<T> getByBioSourceAc( String ac ) {
  return getSession().createCriteria( getEntityClass() )
      .createCriteria( "bioSource" )
      .add( Restrictions.idEq( "ac" ) ).list();
}

代码示例来源:origin: uk.ac.ebi.intact/intact-core

public List<Component> getByInteractorAc( String interactorAc ) {
    return getSession().createCriteria( getEntityClass() )
        .createCriteria( "interactor" )
        .add( Restrictions.idEq( interactorAc ) ).list();
  }
}

代码示例来源:origin: uk.ac.ebi.intact.core/intact-core-readonly

public List<Component> getByInteractorAc( String interactorAc ) {
  return getSession().createCriteria( getEntityClass() )
      .createCriteria( "interactor" )
      .add( Restrictions.idEq( interactorAc ) ).list();
}

代码示例来源:origin: uk.ac.ebi.intact.core/intact-core

public List<Component> getByInteractorAc( String interactorAc ) {
  return getSession().createCriteria( getEntityClass() )
      .createCriteria( "interactor" )
      .add( Restrictions.idEq( interactorAc ) ).list();
}

代码示例来源:origin: uk.ac.ebi.intact.core/intact-core

public List<ComponentConfidence> getByComponentAc( String componentAc ) {
    return getSession().createCriteria( getEntityClass() )
        .createCriteria( "component" )
        .add( Restrictions.idEq(componentAc) ).list();
  }
}

代码示例来源:origin: uk.ac.ebi.intact/intact-core

public List<String> getNestedInteractionAcsByInteractionAc( String interactionAc ) {
  if ( log.isDebugEnabled() ) {
    log.debug( "Getting nested interactions for interaction with ac: " + interactionAc );
  }
  return getSession().createCriteria( InteractionImpl.class )
      .add( Restrictions.idEq( interactionAc ) )
      .createAlias( "components", "comp" )
      .createAlias( "comp.interactor", "interactor" )
      .add( Restrictions.eq( "interactor.objClass", InteractionImpl.class.getName() ) )
      .setProjection( Projections.distinct( Projections.property( "interactor.ac" ) ) ).list();
}

代码示例来源:origin: uk.ac.ebi.intact.core/intact-core-readonly

public List<Experiment> getByHostOrganism(String biosourceAc){
  return getSession().createCriteria(getEntityClass())
      .createCriteria("bioSource")
      .add(Restrictions.idEq(biosourceAc)).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list();
}

相关文章