-->
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.  [ 3 posts ] 
Author Message
 Post subject: Eclipse RCP - no persistent classes found for query class
PostPosted: Mon Oct 17, 2011 7:14 am 
Newbie

Joined: Mon Oct 17, 2011 6:57 am
Posts: 2
Hi,

first of all, please excuse my poor English.

I've created an Eclipse RCP Plugin-Project with a view. The view should show articles that are stored in my database.

That's how Article.java looks like:

Code:
package model;

import javax.persistence.Column;
import javax.persistence.Entity;

@SuppressWarnings("serial")
@Entity
public class Article extends BaseEntity {

   @Column(nullable = false, unique = true)
   private String number;

   @Column(nullable = false)
   private String name;

   private float price;
   
   public String getNumber() {
      return number;
   }

   public void setNumber(String number) {
      this.number = number;
   }

   public String getName() {
      return name;
   }

   public void setName(String name) {
      this.name = name;
   }

   public float getPrice() {
      return price;
   }

   public void setPrice(float price) {
      this.price = price;
   }
}


The model provider:

Code:
package model;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

public class ModelProvider {
   public static  ModelProvider INSTANCE = null;
   private List<Article> articles;

   @SuppressWarnings("unchecked")
   private ModelProvider()
   {
      EntityManagerFactory emf = Persistence.createEntityManagerFactory("adb");

      // First unit of work
      EntityManager em = emf.createEntityManager();
      EntityTransaction tx = em.getTransaction();
      
      tx.begin();
      List l = em.createQuery("select a from model.Article a").getResultList();
      articles = new ArrayList<Article>();
      for(Iterator i = l.iterator(); i.hasNext();)
      {
          Article a = (Article) i.next();
          articles.add(a);
      }
      //System.out.println(articles.get(0).getName());
   }
   
   public List<Article> getArticles() {
      return articles;
   }
   
   public static ModelProvider getInstance()
   {
      if (INSTANCE == null) {
         INSTANCE = new ModelProvider();
      }
      
      return INSTANCE;
   }
}


The View:

Code:
package toolproject;

import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;

import model.Article;
import model.ModelProvider;

public class View extends ViewPart {
   public static final String ID = "ToolProject.view";

   private TableViewer viewer;
   // We use icons
   

   public void createPartControl(Composite parent) {
      GridLayout layout = new GridLayout(2, false);
      parent.setLayout(layout);
      Label searchLabel = new Label(parent, SWT.NONE);
      searchLabel.setText("Search: ");
      final Text searchText = new Text(parent, SWT.BORDER | SWT.SEARCH);
      searchText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
            | GridData.HORIZONTAL_ALIGN_FILL));
      createViewer(parent);
   }

   private void createViewer(Composite parent) {
      viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
            | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
      createColumns(parent, viewer);
      final Table table = viewer.getTable();
      table.setHeaderVisible(true);
      table.setLinesVisible(true);

      viewer.setContentProvider(new ArrayContentProvider());
      // Get the content for the viewer, setInput will call getElements in the
      // contentProvider
      viewer.setInput(ModelProvider.getInstance().getArticles());
      // Make the selection available to other views
      getSite().setSelectionProvider(viewer);
      // Set the sorter for the table

      // Layout the viewer
      GridData gridData = new GridData();
      gridData.verticalAlignment = GridData.FILL;
      gridData.horizontalSpan = 2;
      gridData.grabExcessHorizontalSpace = true;
      gridData.grabExcessVerticalSpace = true;
      gridData.horizontalAlignment = GridData.FILL;
      viewer.getControl().setLayoutData(gridData);
   }

   public TableViewer getViewer() {
      return viewer;
   }

   // This will create the columns for the table
   private void createColumns(final Composite parent, final TableViewer viewer) {
      String[] titles = { "Number", "Name", "Price"};
      int[] bounds = { 100, 100, 100};

      // First column is for the first name
      TableViewerColumn col = createTableViewerColumn(titles[0], bounds[0], 0);
      col.setLabelProvider(new ColumnLabelProvider() {
         @Override
         public String getText(Object element) {
            Article a = (Article) element;
            return a.getNumber();
         }
      });

      // Second column is for the last name
      col = createTableViewerColumn(titles[1], bounds[1], 1);
      col.setLabelProvider(new ColumnLabelProvider() {
         @Override
         public String getText(Object element) {
            Article a = (Article) element;
            return a.getName();
         }
      });

      // Now the gender
      col = createTableViewerColumn(titles[2], bounds[2], 2);
      col.setLabelProvider(new ColumnLabelProvider() {
         @Override
         public String getText(Object element) {
            Article a = (Article) element;
            return ""+a.getPrice();
         }
      });
   }

   private TableViewerColumn createTableViewerColumn(String title, int bound, final int colNumber) {
      final TableViewerColumn viewerColumn = new TableViewerColumn(viewer,
            SWT.NONE);
      final TableColumn column = viewerColumn.getColumn();
      column.setText(title);
      column.setWidth(bound);
      column.setResizable(true);
      column.setMoveable(true);
      return viewerColumn;

   }

   
/**
    * Passing the focus request to the viewer's control.
    */

   public void setFocus() {
      viewer.getControl().setFocus();
   }
}


persistence.xml

Code:
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
        http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">

    <!-- JPA test "unit" -->
    <persistence-unit name="adb" transaction-type="RESOURCE_LOCAL" >
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
            <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
         
            <property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/prog"/>
            <property name="hibernate.connection.username" value="postgres"/>
            <property name="hibernate.connection.password" value="postgres"/>
            <property name="hibernate.connection.pool_size" value="5"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
            <property name="hibernate.show_sql" value="true"/>
            <property name="hibernate.format_sql" value="true"/>
        </properties>
    </persistence-unit>

</persistence>

I can see the view with the table in it but the data sets from my table are not fetched due to following exception:

Quote:
17.10.2011 13:08:43 org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.0.CR2}
17.10.2011 13:08:43 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.0.0.CR4}
17.10.2011 13:08:43 org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
17.10.2011 13:08:43 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
17.10.2011 13:08:43 org.hibernate.ejb.packaging.InputStreamZippedJarVisitor doProcessElements
WARN: HHH015010: Unable to find file (ignored): bundleresource://27.fwk25860399
java.io.FileNotFoundException: C:\workspace\ToolProject\bin (access is denied)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at org.eclipse.osgi.framework.util.SecureAction.getFileInputStream(SecureAction.java:124)
at org.eclipse.osgi.baseadaptor.bundlefile.FileBundleEntry.getInputStream(FileBundleEntry.java:56)
at org.eclipse.osgi.framework.internal.core.BundleURLConnection.connect(BundleURLConnection.java:53)
at org.eclipse.osgi.framework.internal.core.BundleURLConnection.getInputStream(BundleURLConnection.java:99)
at java.net.URL.openStream(Unknown Source)
at org.hibernate.ejb.packaging.InputStreamZippedJarVisitor.doProcessElements(InputStreamZippedJarVisitor.java:60)
at org.hibernate.ejb.packaging.AbstractJarVisitor.getMatchingEntries(AbstractJarVisitor.java:148)
at org.hibernate.ejb.packaging.NativeScanner.getClassesInJar(NativeScanner.java:126)
at org.hibernate.ejb.Ejb3Configuration.addScannedEntries(Ejb3Configuration.java:482)
at org.hibernate.ejb.Ejb3Configuration.addMetadataFromScan(Ejb3Configuration.java:472)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:358)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:55)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at model.ModelProvider.<init>(ModelProvider.java:38)
at model.ModelProvider.getInstance(ModelProvider.java:62)
at toolproject.View.createViewer(View.java:49)
at toolproject.View.createPartControl(View.java:35)
at org.eclipse.ui.internal.ViewReference.createPartHelper(ViewReference.java:367)
at org.eclipse.ui.internal.ViewReference.createPart(ViewReference.java:226)
at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:595)
at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:313)
at org.eclipse.ui.internal.ViewPane.setVisible(ViewPane.java:529)
at org.eclipse.ui.internal.presentations.PresentablePart.setVisible(PresentablePart.java:180)
at org.eclipse.ui.internal.presentations.util.PresentablePartFolder.select(PresentablePartFolder.java:270)
at org.eclipse.ui.internal.presentations.util.LeftToRightTabOrder.select(LeftToRightTabOrder.java:65)
at org.eclipse.ui.internal.presentations.util.TabbedStackPresentation.selectPart(TabbedStackPresentation.java:473)
at org.eclipse.ui.internal.PartStack.refreshPresentationSelection(PartStack.java:1256)
at org.eclipse.ui.internal.PartStack.setSelection(PartStack.java:1209)
at org.eclipse.ui.internal.PartStack.showPart(PartStack.java:1608)
at org.eclipse.ui.internal.PartStack.createControl(PartStack.java:649)
at org.eclipse.ui.internal.PartStack.createControl(PartStack.java:576)
at org.eclipse.ui.internal.PartSashContainer.createControl(PartSashContainer.java:568)
at org.eclipse.ui.internal.PerspectiveHelper.activate(PerspectiveHelper.java:272)
at org.eclipse.ui.internal.Perspective.onActivate(Perspective.java:982)
at org.eclipse.ui.internal.WorkbenchPage.onActivate(WorkbenchPage.java:2626)
at org.eclipse.ui.internal.WorkbenchWindow$27.run(WorkbenchWindow.java:2965)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.ui.internal.WorkbenchWindow.setActivePage(WorkbenchWindow.java:2946)
at org.eclipse.ui.internal.WorkbenchWindow.busyOpenPage(WorkbenchWindow.java:761)
at org.eclipse.ui.internal.Workbench$21.runWithException(Workbench.java:1045)
at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:134)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3885)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3506)
at org.eclipse.ui.application.WorkbenchAdvisor.openWindows(WorkbenchAdvisor.java:803)
at org.eclipse.ui.internal.Workbench$28.runWithException(Workbench.java:1384)
at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:179)
at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:150)
at org.eclipse.swt.widgets.Display.syncExec(Display.java:4342)
at org.eclipse.ui.internal.StartupThreading.runWithoutExceptions(StartupThreading.java:94)
at org.eclipse.ui.internal.Workbench.init(Workbench.java:1379)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2335)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2221)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:500)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:493)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at toolproject.Application.start(Application.java:20)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:194)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:368)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:559)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
at org.eclipse.equinox.launcher.Main.main(Main.java:1287)
17.10.2011 13:08:43 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
17.10.2011 13:08:43 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 5
17.10.2011 13:08:43 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: true
17.10.2011 13:08:43 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [org.postgresql.Driver] at URL [jdbc:postgresql://localhost:5432/prog]
17.10.2011 13:08:43 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {user=postgres, password=****, autocommit=true, release_mode=auto}
17.10.2011 13:08:43 org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
17.10.2011 13:08:43 org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
17.10.2011 13:08:43 org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
17.10.2011 13:08:43 org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
17.10.2011 13:08:43 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000228: Running hbm2ddl schema update
17.10.2011 13:08:43 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000102: Fetching database metadata
17.10.2011 13:08:44 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000396: Updating schema
17.10.2011 13:08:44 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000232: Schema update complete
17.10.2011 13:08:44 org.hibernate.hql.internal.QuerySplitter concreteQueries
WARN: HHH000183: no persistent classes found for query class: select a from model.Article a


Any ideas how to solve this issue?

Thank you in advance!


Top
 Profile  
 
 Post subject: Re: Eclipse RCP - no persistent classes found for query class
PostPosted: Tue Oct 18, 2011 10:07 am 
Newbie

Joined: Mon Oct 17, 2011 6:57 am
Posts: 2
For everybody who suffers with this exception, I have solved it by putting the persistence.xml in the same diretory where hibernate-entitymanager-4.0.0.CR4.jar is located.

Maybe this helps you as well.


wintersleep


Top
 Profile  
 
 Post subject: Re: Eclipse RCP - no persistent classes found for query class
PostPosted: Wed Apr 19, 2017 2:59 pm 
Newbie

Joined: Wed Apr 19, 2017 2:44 pm
Posts: 1
Hi

I am not getting any results, got the below warning message
WARN: HHH000183: no persistent classes found for query class: from com.persistent.Employees

Could you please help us to solve this problem.

Thank you in advance.

package com.persistent;

import java.io.File;
import java.util.List;


import org.hibernate.Session;
import org.hibernate.Transaction;

public class Test {


@SuppressWarnings("deprecation")
public static void main(String[] args) {
// TODO Auto-generated method stub




List<com.persistent.Employees> employeesList=null;
Session session = HibernateUtil.getSessionFactory().openSession();

if(session.isOpen()){
System.out.println("Session");
}

Transaction trnsction = session.beginTransaction();


System.out.println(session.createQuery("from com.persistent.Employees").list().size());
/*employeesList= lQuery.getResultList();
System.out.println("employee list"+ employeesList.size());

if(employeesList!=null && employeesList.size()>0){




for(Employees e:employeesList){
System.out.println(e.getEmployeeId()+" : "+ e.getFirstName()+" : "+e.getLastName());
}


}else{
System.out.println("Nothing is here to print");
}*/

trnsction.commit();
session.close();




}



}


Employee hbm

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 12 Apr, 2017 12:49:53 AM by Hibernate Tools 3.5.0.Final -->
<hibernate-mapping>
<class name="com.persistent.Employees" table="EMPLOYEES">
<id name="employeeId" type="long">
<column name="EMPLOYEE_ID" />
<generator class="assigned" />
</id>
<property name="firstName" type="java.lang.String">
<column name="FIRST_NAME" />
</property>
<property name="hiredate" type="java.util.Date">
<column name="HIRE_DATE" />
</property>
<property name="jobId" type="java.lang.String">
<column name="JOB_ID" />
</property>
<property name="phoneNumber" type="java.lang.String">
<column name="PHONE_NUMBER" />
</property>
<property name="departmentId" type="java.lang.Integer">
<column name="DEPARTMENT_ID" />
</property>
<property name="commissionpct" type="java.lang.Integer">
<column name="COMMISSION_PCT" />
</property>
<property name="managerId" type="java.lang.Integer">
<column name="MANAGER_ID" />
</property>
<property name="lastName" type="java.lang.String">
<column name="LAST_NAME" />
</property>
<property name="salary" type="java.lang.Integer">
<column name="SALARY" />
</property>
</class>
</hibernate-mapping>


hibernate cfg file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:XE</property>
<property name="hibernate.connection.password">velan1982</property>
<property name="hibernate.connection.username">SYSTEM</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<property name="hibernate.show_sql">true</property>
<mapping class="com.persistent.Department" package="com.persistent" resource="com/persistent/Department.hbm.xml"/>
<mapping class="com.persistent.Location" package="com.persistent" resource="com/persistent/Location.hbm.xml"/>
<mapping class="com.persistent.Countries"
package="com.persistent.Department" resource="com/persistent/Countries.hbm.xml"/>
<mapping class="com.persistent.Job" package="com.persistent" resource="com/persistent/Job.hbm.xml"/>
<mapping class="com.persistent.JobGrades" package="com.persistent" resource="com/persistent/JobGrades.hbm.xml"/>
<mapping class="com.persistent.JobHistor" package="com.persistent" resource="com/persistent/JobHistor.hbm.xml"/>
<mapping class="com.persistent.Employees" package="com.persistent" resource="com/persistent/Employees.hbm.xml"/>
</session-factory>
</hibernate-configuration>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.