Persistencia de dados JPA

2 respostas
joede.fadel

to usando o netbeans 6 tenho a seguinte classe

/*
* tabela.java
*
* Created on 25 de Setembro de 2007, 21:11
*/

package logs;

import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.Query;

/**
*
* @author Joede
*/


public class tabela extends javax.swing.JFrame {

/** Creates new form tabela */
public tabela() {
initComponents();
// try{
// ResultSet rs = (ResultSet) aulaQuery.getResultList();
// while(rs.next())
// System.out.println(rs.getString(1));
// }catch(Exception e){}
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/

// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
bindingContext = new javax.beans.binding.BindingContext();

logsPUEntityManager = javax.persistence.Persistence.createEntityManagerFactory("logsPU").createEntityManager();
aulaQuery = logsPUEntityManager.createQuery("SELECT a FROM Aula a ");
aulaList = aulaQuery.getResultList();
list1 = ((javax.persistence.Query)null).getResultList();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jScrollPane2 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

javax.beans.binding.Binding binding = new javax.beans.binding.Binding(aulaList, null, jTable1, "elements");
javax.beans.binding.Binding childBinding = binding.addChildBinding("${applicationName}", null);
childBinding.putParameter(javax.swing.binding.ParameterKeys.COLUMN, 0);
childBinding.putParameter(javax.swing.binding.ParameterKeys.COLUMN_CLASS, String.class);
childBinding = binding.addChildBinding("${textData}", null);
childBinding.putParameter(javax.swing.binding.ParameterKeys.COLUMN, 1);
childBinding.putParameter(javax.swing.binding.ParameterKeys.COLUMN_CLASS, String.class);
childBinding = binding.addChildBinding("${cpu}", null);
childBinding.putParameter(javax.swing.binding.ParameterKeys.COLUMN, 2);
childBinding.putParameter(javax.swing.binding.ParameterKeys.COLUMN_CLASS, Integer.class);
childBinding = binding.addChildBinding("${duration}", null);
childBinding.putParameter(javax.swing.binding.ParameterKeys.COLUMN, 3);
childBinding.putParameter(javax.swing.binding.ParameterKeys.COLUMN_CLASS, java.math.BigInteger.class);
childBinding = binding.addChildBinding("${reads}", null);
childBinding.putParameter(javax.swing.binding.ParameterKeys.COLUMN, 4);
childBinding.putParameter(javax.swing.binding.ParameterKeys.COLUMN_CLASS, java.math.BigInteger.class);
childBinding = binding.addChildBinding("${writes}", null);
childBinding.putParameter(javax.swing.binding.ParameterKeys.COLUMN, 5);
childBinding.putParameter(javax.swing.binding.ParameterKeys.COLUMN_CLASS, java.math.BigInteger.class);
bindingContext.addBinding(binding);
binding.bind();

jScrollPane1.setViewportView(jTable1);

jTextArea1.setColumns(20);
jTextArea1.setRows(5);

bindingContext.addBinding(jTable1, "${selectedElement.textData}", jTextArea1, "text");

jScrollPane2.setViewportView(jTextArea1);

jButton1.setText("Copiar");
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton1MouseClicked(evt);
}
});

jButton2.setText("jButton2");
jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton2MouseClicked(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(72, 72, 72)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 199, Short.MAX_VALUE)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(46, 46, 46))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(86, 86, 86)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(27, 27, 27)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton2)
.addComponent(jButton1))
.addContainerGap())
);

bindingContext.bind();

pack();
}// </editor-fold>


/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new tabela().setVisible(true);
}
});
}

// Variables declaration - do not modify
private java.util.List<logs.Aula> aulaList;
private javax.persistence.Query aulaQuery;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTable jTable1;
private javax.swing.JTextArea jTextArea1;
private java.util.List list1;
private javax.persistence.EntityManager logsPUEntityManager;
private javax.beans.binding.BindingContext bindingContext;
// End of variables declaration

}

ta dando o seguinte erro

init:
deps-jar:
Deleted 4 out of date files in 0 seconds
Compiling 1 source file to C:\Documents and Settings\pos\Desktop\logs\build\classes
Note: C:\Documents and Settings\pos\Desktop\logs\src\logs\tabela.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
compile:
run:
[TopLink Info]: 2007.09.28 08:56:32.546--ServerSession(15401342)--TopLink, version: Oracle TopLink Essentials - 9.1 (Build b36-rc)
28/09/2007 20:56:32 com.microsoft.sqlserver.jdbc.AuthenticationJNI <clinit>
WARNING: Failed to load the sqljdbc_auth.dll
[TopLink Info]: 2007.09.28 08:56:33.062--ServerSession(15401342)--file:/C:/Documents%20and%20Settings/pos/Desktop/logs/build/classes/-logsPU login successful
Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
at com.microsoft.sqlserver.jdbc.TDSPacket.<init>(Unknown Source)
at com.microsoft.sqlserver.jdbc.TDSReader.readPacket(Unknown Source)
at com.microsoft.sqlserver.jdbc.TDSReader.readResponse(Unknown Source)
at com.microsoft.sqlserver.jdbc.TDSCommand.startResponse(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(Unknown Source)
[TopLink Info]: 2007.09.28 08:56:38.234--ServerSession(15401342)--file:/C:/Documents%20and%20Settings/pos/Desktop/logs/build/classes/-logsPU logout successful
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(Unknown Source)
at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.executeSelect(DatabaseAccessor.java:711)
at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:486)
at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:437)
at oracle.toplink.essentials.threetier.ServerSession.executeCall(ServerSession.java:465)
at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:213)
at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:199)
at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:270)
at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:600)
at oracle.toplink.essentials.internal.queryframework.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2207)
at oracle.toplink.essentials.internal.queryframework.ExpressionQueryMechanism.selectAllReportQueryRows(ExpressionQueryMechanism.java:2173)
at oracle.toplink.essentials.queryframework.ReportQuery.executeDatabaseQuery(ReportQuery.java:774)
at oracle.toplink.essentials.queryframework.DatabaseQuery.execute(DatabaseQuery.java:609)
at oracle.toplink.essentials.queryframework.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:677)
at oracle.toplink.essentials.queryframework.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:731)
at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2219)
at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:937)
at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:909)
at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.executeReadQuery(EJBQueryImpl.java:346)
at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.getResultList(EJBQueryImpl.java:453)
at logs.tabela.initComponents(tabela.java:45)
at logs.tabela.<init>(tabela.java:25)
BUILD SUCCESSFUL (total time: 8 seconds)

2 Respostas

joede.fadel

aulaQuery = logsPUEntityManager.createQuery("SELECT a FROM Aula a ").setMaxResults(30000);

se eu delimitar o tamanho da minha query de dados dai da certo, soh q eu a minha tabela tem mais de
150 mil linhas

como que faço pra conseguir pegar as 150 mil linhas???

grato :? :?:

joede.fadel

alguem sabe qual é o motivo desse erro, até agora eu naum consegui resolve-lo.

:?: :?: :?: :?: :?: :?: :?: :?: :?: :?: :?: :?: :?: :?: :?: :?: :?: :?: :?: :?:

Criado 28 de setembro de 2007
Ultima resposta 16 de out. de 2007
Respostas 2
Participantes 1