-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 
Author Message
 Post subject: Cassandra select all query is not working
PostPosted: Thu Feb 25, 2016 12:15 pm 
Newbie

Joined: Thu Feb 25, 2016 12:08 pm
Posts: 6
I am not able to retrieve all details from Cassandra database table using hibernate OGM. Please give me suggestions.

Here is my Code:

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.search.annotations.Indexed;


@Entity
@Indexed
@Table(name="student")
public class Student implements Serializable {

@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name="uuid", strategy="uuid2")
private String id;

@Column(name="std_name")
private String std_name ;

public String getId() {
return id;
}

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

public String getStd_name() {
return std_name;
}

public void setStd_name(String std_name) {
this.std_name = std_name;
}

}

Hibernate OGM Configuration:

import org.hibernate.cfg.Environment;
import org.hibernate.ogm.cfg.OgmConfiguration;


public class HOGMDao {

public OgmConfiguration hogmdao(String db){

OgmConfiguration cfgogm = new OgmConfiguration();

try {

cfgogm.setProperty(Environment.TRANSACTION_STRATEGY,"org.hibernate.transaction.JTATransactionFactory");
cfgogm.setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS, "jta");
cfgogm.setProperty(Environment.JTA_PLATFORM,"org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform");
cfgogm.setProperty("com.arjuna.ats.jta.jtaTMImplementation","com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple");
cfgogm.setProperty("com.arjuna.ats.jta.jtaUTImplementation","com.arjuna.ats.internal.jta.transaction.arjunacore.UserTransactionImple");
cfgogm.setProperty("hibernate.ogm.datastore.provider", "CASSANDRA_EXPERIMENTAL");
cfgogm.setProperty("hibernate.ogm.datastore.database", db);
cfgogm.setProperty("hibernate.ogm.datastore.host", "127.0.0.1");
cfgogm.setProperty("hibernate.ogm.datastore.port", "9042");
cfgogm.addAnnotatedClass(Student.class);

}
catch (Exception e) {

}

return cfgogm;
}

}

Getstudentdetails.java :

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.ogm.cfg.OgmConfiguration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;


public class Getstudentdetails{

private static SessionFactory sessionFactory;
private static ServiceRegistry serviceRegistry;


public void getStudent() {

try{

HOGMDao dd=new HOGMDao();
OgmConfiguration cfgogm = dd.hogmdao("student");


serviceRegistry = new ServiceRegistryBuilder().applySettings(cfgogm.getProperties()).
buildServiceRegistry();
sessionFactory = cfgogm.buildSessionFactory(serviceRegistry);

com.arjuna.ats.jta.TransactionManager.transactionManager();
javax.transaction.UserTransaction tx = com.arjuna.ats.jta.UserTransaction.userTransaction();

tx.begin();

Session cs = sessionFactory.getCurrentSession();

List list = cs.createQuery("FROM Student").list();

tx.commit();

Iterator iterator = list.iterator();

for (;iterator.hasNext();){

Student std= (Student) iterator.next();
System.out.println("Student_Id : " + std.getId());
System.out.println("Student Name : " + std.getStd_name());

}
}
catch(Exception e){
}
}
}

I am not able to get student details from database.


Top
 Profile  
 
 Post subject: Re: Cassandra select all query is not working
PostPosted: Mon Feb 29, 2016 9:03 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
The following code should work.
Note that you didn't specify what exception you are seeing and which JDK, cassandra and OGM version you are using.
So, I've tested it with the latest OGM, JDK 8 and Cassandra 2.2.5

Let me know if it does not solve your issue or if you have more questions.

I removed some properties from the configuration (they should not be needed) and replaced them with the constant one to make sure there are no errors.
Note that if you are using the default port on localhost you can remove the HOST property as well.

Code:
import org.hibernate.ogm.cfg.OgmConfiguration;
import org.hibernate.ogm.cfg.OgmProperties;
import org.hibernate.ogm.datastore.impl.AvailableDatastoreProvider;

public class HOGMDao {

   public OgmConfiguration hogmdao(String db) {

      OgmConfiguration cfgogm = new OgmConfiguration();

      try {
         cfgogm.setProperty( OgmProperties.DATASTORE_PROVIDER, AvailableDatastoreProvider.CASSANDRA_EXPERIMENTAL.name() );
         cfgogm.setProperty( OgmProperties.DATABASE, db );
         cfgogm.setProperty( OgmProperties.HOST, "127.0.0.1:9042");
         return cfgogm;
      }
      catch (Exception e) {
         throw new RuntimeException( e );
      }
   }
}


I've change the class to test the configuration in the following way:

Code:
import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.ogm.cfg.OgmConfiguration;

public class Getstudentdetails {

   private static SessionFactory sessionFactory;

   private static void initSessionFactory() {
      HOGMDao dd = new HOGMDao();
      OgmConfiguration cfgogm = dd.hogmdao( "student" );

      StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings( cfgogm.getProperties() ).build();

      MetadataSources sources = new MetadataSources().addAnnotatedClass( Student.class );
      Metadata metadata = sources.getMetadataBuilder( serviceRegistry ).build();

      sessionFactory = metadata.getSessionFactoryBuilder().build();
   }

   private static void closeSessionFactory() {
      sessionFactory.close();
   }

   public void getStudent() {
      try ( Session cs = sessionFactory.openSession() ) {
         Transaction tx = cs.beginTransaction();
         tx.begin();

         @SuppressWarnings("unchecked")
         List<Student> list = cs.createQuery( "FROM Student" ).list();

         tx.commit();

         for ( Student student : list ) {
            System.out.println( "Student_Id : " + student.getId() );
            System.out.println( "Student Name : " + student.getStd_name() );
         }
      }
   }

   private static void createStudent(String name) {
      try ( Session cs = sessionFactory.openSession() ) {
         Transaction tx = cs.beginTransaction();
         tx.begin();
         Student student = new Student();
         student.setStd_name( name );
         cs.persist( student );
         tx.commit();
      }
   }

   /**
    * MAIN
    */
   public static void main(String[] args) {
      initSessionFactory();
      try {
                        // Create some students in case the db is empty
         createStudent( "John Doe" );
         createStudent( "Jane Doe" );

         new Getstudentdetails().getStudent();
      }
      finally {
         // Make sure the session factory is closed before termination
         closeSessionFactory();
      }
   }
}


Hope this help,
Davide


Top
 Profile  
 
 Post subject: Re: Cassandra select all query is not working
PostPosted: Mon Feb 29, 2016 11:34 pm 
Newbie

Joined: Thu Feb 25, 2016 12:08 pm
Posts: 6
Thank you for your response, I didn't get any exceptions. I am using Hibernate OGM 4.2.0, Cassandra 2.1.7 and jdk 7.
I will confirm you after testing. Thank you.


Top
 Profile  
 
 Post subject: Re: Cassandra select all query is not working
PostPosted: Tue Mar 01, 2016 7:55 am 
Newbie

Joined: Thu Feb 25, 2016 12:08 pm
Posts: 6
I am getting the following error after executing code, I used latest hibernate OGM version(5.0.0.Beta1).

Error :

Mar 01, 2016 5:00:10 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.0.5.Final}
Mar 01, 2016 5:00:10 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Mar 01, 2016 5:00:10 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Mar 01, 2016 5:00:11 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
Mar 01, 2016 5:00:11 PM org.hibernate.ogm.datastore.impl.DatastoreProviderInitiator initiateService
INFO: OGM000016: NoSQL Datastore provider: org.hibernate.ogm.datastore.cassandra.impl.CassandraDatastoreProvider
Mar 01, 2016 5:00:11 PM org.hibernate.ogm.datastore.cassandra.impl.CassandraDatastoreProvider start
INFO: OGM001601: Connecting to Cassandra at 127.0.0.1:9042
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Mar 01, 2016 5:00:12 PM org.hibernate.ogm.dialect.impl.GridDialectInitiator$GridDialectInstantiator newInstance
INFO: OGM000017: Grid Dialect: org.hibernate.ogm.datastore.cassandra.CassandraDialect
Mar 01, 2016 5:00:12 PM org.hibernate.ogm.dialect.impl.GridDialectInitiator$GridDialectInstantiator newInstance
INFO: Grid dialect logs are disabled
Mar 01, 2016 5:00:12 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.ogm.dialect.impl.OgmDialect
Mar 01, 2016 5:00:12 PM org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl makeLobCreatorBuilder
INFO: HHH000422: Disabling contextual LOB creation as connection was null
Mar 01, 2016 5:00:13 PM org.hibernate.ogm.cfg.impl.Version <clinit>
INFO: OGM000001: Hibernate OGM 5.0.0.Beta1
Exception in thread "main" java.lang.AbstractMethodError
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:278)
at org.hibernate.ogm.boot.impl.OgmSessionFactoryBuilderImpl.build(OgmSessionFactoryBuilderImpl.java:54)
at org.hibernate.ogm.boot.impl.OgmSessionFactoryBuilderImpl.build(OgmSessionFactoryBuilderImpl.java:23)
at com.brisq.dao.Getuserdetails.initSessionFactory(Getuserdetails.java:32)
at com.brisq.dao.Getuserdetails.main(Getuserdetails.java:60)

Thank you.


Top
 Profile  
 
 Post subject: Re: Cassandra select all query is not working
PostPosted: Wed Mar 02, 2016 6:15 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
Can you try this:

Code:
package org.hibernate.ogm.datastore.cassandra.forum;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.ogm.cfg.OgmConfiguration;

public class Getstudentdetails {

   private static SessionFactory sessionFactory;

   private static void initSessionFactory() {
      HOGMDao dd = new HOGMDao();
      OgmConfiguration cfgogm = dd.hogmdao( "student" );
      StandardServiceRegistry registry = new StandardServiceRegistryBuilder().applySettings( cfgogm.getProperties() ).build();
      sessionFactory = cfgogm.buildSessionFactory( registry );
   }

   private static void closeSessionFactory() {
      sessionFactory.close();
   }

   public void getStudent() {
      Session cs = null;
      try {
         cs = sessionFactory.openSession();
         Transaction tx = cs.beginTransaction();

         @SuppressWarnings("unchecked")
         List<Student> list = cs.createQuery( "FROM Student" ).list();

         tx.commit();

         for ( Student student : list ) {
            System.out.println( "Student_Id : " + student.getId() );
            System.out.println( "Student Name : " + student.getStd_name() );
         }
      }
      finally {
         cs.close();
      }
   }

   private static void createStudent(String name) {
      Session cs = null;
      Transaction tx = null;
      try {
         cs = sessionFactory.openSession();
         tx = cs.beginTransaction();
         Student student = new Student();
         student.setStd_name( name );
         cs.persist( student );
         tx.commit();
      }
      catch ( Exception e) {
         tx.rollback();
      }
      finally {
         cs.close();
      }
   }

   public static void main(String[] args) {
      initSessionFactory();
      try {
         createStudent( "John Doe" );
         createStudent( "Jane Doe" );
         new Getstudentdetails().getStudent();
      }
      finally {
         closeSessionFactory();
      }
   }
}


It should work with both Hibernate OGM 4 and 5 and I've tested it with Casandra 2.1.13 and 2.2.5 (with jdk7).
I found an error in my previous example, in some places the transaction was opened twice.

Davide


Top
 Profile  
 
 Post subject: Re: Cassandra select all query is not working
PostPosted: Thu Mar 03, 2016 7:46 am 
Newbie

Joined: Thu Feb 25, 2016 12:08 pm
Posts: 6
Thank you for your reply. I tried with given code, when I placed indexed annotation in POJO(Student) class getting following error.

Error:

INFO: OGM000001: Hibernate OGM 4.2.0.Final
Mar 03, 2016 5:10:12 PM org.hibernate.search.engine.Version <clinit>
INFO: HSEARCH000034: Hibernate Search 5.3.0.Beta2
Mar 03, 2016 5:10:13 PM org.hibernate.internal.SessionFactoryImpl buildCurrentSessionContext
WARN: HHH000008: JTASessionContext being used with JDBCTransactionFactory; auto-flush will not operate correctly with getCurrentSession()
Mar 03, 2016 5:10:13 PM org.hibernate.search.engine.impl.ConfigContext getLuceneMatchVersion
WARN: HSEARCH000075: Configuration setting hibernate.search.lucene_version was not specified: using LUCENE_CURRENT.
Mar 03, 2016 5:10:13 PM org.hibernate.ogm.datastore.cassandra.impl.CassandraDatastoreProvider stop
INFO: OGM001602: Closing connection to Cassandra
Exception in thread "main" java.lang.NullPointerException
at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.packageInfo(AnnotationMetadataProvider.java:138)
at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.getTypeMetadataFor(AnnotationMetadataProvider.java:121)
at org.hibernate.search.spi.SearchIntegratorBuilder.initDocumentBuilders(SearchIntegratorBuilder.java:373)
at org.hibernate.search.spi.SearchIntegratorBuilder.buildNewSearchFactory(SearchIntegratorBuilder.java:199)
at org.hibernate.search.spi.SearchIntegratorBuilder.buildSearchIntegrator(SearchIntegratorBuilder.java:117)
at org.hibernate.search.hcore.impl.HibernateSearchSessionFactoryObserver.sessionFactoryCreated(HibernateSearchSessionFactoryObserver.java:66)
at org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryCreated(SessionFactoryObserverChain.java:52)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:588)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859)
at Getuserdetails.initSessionFactory(Getuserdetails.java:24)
at Getuserdetails.main(Getuserdetails.java:58)
Java Result: 1



when I remove indexed annotation, I am able insert details in to database but not able to retrieve those details from database.
I am getting following error.



Error:

Exception in thread "main" org.hibernate.search.exception.SearchException: Can't build query for type Student which is neither indexed nor has any indexed sub-types.
at org.hibernate.search.query.dsl.impl.ConnectedQueryContextBuilder$HSearchEntityContext.<init>(ConnectedQueryContextBuilder.java:47)
at org.hibernate.search.query.dsl.impl.ConnectedQueryContextBuilder.forEntity(ConnectedQueryContextBuilder.java:33)
at org.hibernate.hql.lucene.internal.builder.predicate.LucenePredicateFactory.getRootPredicate(LucenePredicateFactory.java:77)
at org.hibernate.hql.ast.spi.SingleEntityQueryBuilder.setEntityType(SingleEntityQueryBuilder.java:76)
at org.hibernate.hql.ast.spi.SingleEntityQueryRendererDelegate.registerPersisterSpace(SingleEntityQueryRendererDelegate.java:117)
at org.hibernate.hql.ast.render.QueryRenderer.entityName(QueryRenderer.java:12331)
at org.hibernate.hql.ast.render.QueryRenderer.persisterSpaceRoot(QueryRenderer.java:3063)
at org.hibernate.hql.ast.render.QueryRenderer.persisterSpace(QueryRenderer.java:2955)
at org.hibernate.hql.ast.render.QueryRenderer.persisterSpaces(QueryRenderer.java:2892)
at org.hibernate.hql.ast.render.QueryRenderer.fromClause(QueryRenderer.java:2802)
at org.hibernate.hql.ast.render.QueryRenderer.selectFrom(QueryRenderer.java:2703)
at org.hibernate.hql.ast.render.QueryRenderer.querySpec(QueryRenderer.java:2181)
at org.hibernate.hql.ast.render.QueryRenderer.queryExpression(QueryRenderer.java:2105)
at org.hibernate.hql.ast.render.QueryRenderer.queryStatement(QueryRenderer.java:1744)
at org.hibernate.hql.ast.render.QueryRenderer.queryStatementSet(QueryRenderer.java:1657)
at org.hibernate.hql.ast.render.QueryRenderer.statement(QueryRenderer.java:653)
at org.hibernate.hql.ast.spi.QueryRendererProcessor.process(QueryRendererProcessor.java:51)
at org.hibernate.hql.QueryParser.parseQuery(QueryParser.java:82)
at org.hibernate.ogm.query.impl.FullTextSearchQueryTranslator.getLuceneQuery(FullTextSearchQueryTranslator.java:100)
at org.hibernate.ogm.query.impl.FullTextSearchQueryTranslator.list(FullTextSearchQueryTranslator.java:75)
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:236)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1300)
at org.hibernate.internal.QueryImpl.list(QueryImpl.java:103)
at Getuserdetails.getStudent(Getuserdetails.java:40)
at Getuserdetails.main(Getuserdetails.java:62)
Java Result: 1


Top
 Profile  
 
 Post subject: Re: Cassandra select all query is not working
PostPosted: Tue Mar 08, 2016 7:06 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
I've created a repository with these classes on my GitHub: https://github.com/DavideD/forum-example

It seems to work on my machine :)

You can try to run the main class in hibernate.forum.example.Getstudentdetails and let me know if you still have issues.

If it works you have a working (very basic) example.

Cheers,
Davide


Top
 Profile  
 
 Post subject: Re: Cassandra select all query is not working
PostPosted: Wed Mar 09, 2016 12:44 am 
Newbie

Joined: Thu Feb 25, 2016 12:08 pm
Posts: 6
Thank you, Now I am able to retrieve all details from database. I am facing one problem, that is when I insert details into database using one entity class and retrieve details from other entity class with same field names then the details are not getting from database.


Top
 Profile  
 
 Post subject: Re: Cassandra select all query is not working
PostPosted: Wed Mar 09, 2016 7:51 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
Could you write down an example of what you are trying to do?


Top
 Profile  
 
 Post subject: Re: Cassandra select all query is not working
PostPosted: Wed Mar 09, 2016 10:55 am 
Newbie

Joined: Thu Feb 25, 2016 12:08 pm
Posts: 6
For Inserting Details into database:

Code:

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.search.annotations.Indexed;

@Entity
@Indexed
@Table(name = "student")
public class Student implements Serializable {

@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
private String id;

@Column(name = "std_name")
private String std_name;

public String getId() {
return id;
}

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

public String getStd_name() {
return std_name;
}

public void setStd_name(String std_name) {
this.std_name = std_name;
}

}



import org.hibernate.ogm.cfg.OgmConfiguration;
import org.hibernate.ogm.cfg.OgmProperties;
import org.hibernate.ogm.datastore.impl.AvailableDatastoreProvider;
import org.hibernate.search.cfg.Environment;

public class HOGMDao {

public OgmConfiguration hogmdao(String db) {

OgmConfiguration cfgogm = new OgmConfiguration();

try {
cfgogm.setProperty( OgmProperties.DATASTORE_PROVIDER, AvailableDatastoreProvider.CASSANDRA_EXPERIMENTAL.name() );
cfgogm.setProperty( OgmProperties.DATABASE, db );
cfgogm.setProperty( OgmProperties.HOST, "127.0.0.1:9042" );
cfgogm.setProperty( "hibernate.search.default.directory_provider ", "ram" );
return cfgogm;
}
catch (Exception e) {
throw new RuntimeException( e );
}
}
}





import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.ogm.cfg.OgmConfiguration;

public class Insertuserdetails {

private static SessionFactory sessionFactory;

private static void initSessionFactory() {
HOGMDao dd = new HOGMDao();
OgmConfiguration cfgogm = dd.hogmdao( "student" );
cfgogm.addAnnotatedClass(Student.class);
StandardServiceRegistry registry = new StandardServiceRegistryBuilder().applySettings( cfgogm.getProperties() ).build();
sessionFactory = cfgogm.buildSessionFactory( registry );
}

private static void closeSessionFactory() {
sessionFactory.close();
}


private static void createStudent(String name) {
Session cs = null;
Transaction tx = null;
try {
cs = sessionFactory.openSession();
tx = cs.beginTransaction();
Student student = new Student();
student.setStd_name( name );
cs.persist( student );
tx.commit();
}
catch (Exception e) {
tx.rollback();
}
finally {
cs.close();
}
}


public static void main(String[] args) {
initSessionFactory();
try {
createStudent( "John Doe" );
createStudent( "Jane Doe" );

}
finally {
closeSessionFactory();
}
}
}


For Retrieving details I am using another entity class Student2

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.search.annotations.Indexed;

@Entity
@Indexed
@Table(name = "student")
public class Student2 implements Serializable {

@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
private String id;

@Column(name = "std_name")
private String std_name;

public String getId() {
return id;
}

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

public String getStd_name() {
return std_name;
}

public void setStd_name(String std_name) {
this.std_name = std_name;
}

}


import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.ogm.cfg.OgmConfiguration;

public class Getuserdetails {

private static SessionFactory sessionFactory;

private static void initSessionFactory() {
HOGMDao dd = new HOGMDao();
OgmConfiguration cfgogm = dd.hogmdao( "student" );
cfgogm.addAnnotatedClass(Student2.class);
StandardServiceRegistry registry = new StandardServiceRegistryBuilder().applySettings( cfgogm.getProperties() ).build();
sessionFactory = cfgogm.buildSessionFactory( registry );
}

private static void closeSessionFactory() {
sessionFactory.close();
}

public void getStudent() {
Session cs = null;
try {
cs = sessionFactory.openSession();
Transaction tx = cs.beginTransaction();

@SuppressWarnings("unchecked")
List<Student2> list = cs.createQuery( "FROM Student2" ).list();

tx.commit();

for ( Student2 student : list ) {
System.out.println( "Student_Id : " + student.getId() );
System.out.println( "Student Name : " + student.getStd_name() );
}
}
finally {
cs.close();
}
}




public static void main(String[] args) {
initSessionFactory();
try {

new Getuserdetails().getStudent();
}
finally {
closeSessionFactory();
}
}
}


when I am using Student entity class for retrieving details, I am able to retrieve but when I use Student2 entity class details are not getting


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.