K, this is really a GWT forum, not hibernate but I will try to give you some guidance and hopefully it leads you down the right path.
At first glance I am at this moment not able to see anything wrong with the code you have. A couple of suggestions though: a) The transaction in a select statement is really optional. Nothing really needs to be rolled back or treated for the most part as an atomic operation. It doesn't hurt if you want to keep it though. b) I would enable debug and see the sql query that is being generated. Looking at your entity doesn't reveal any associations, but the query can very well be generating a left join hence the list of three results with apparently only the first real row from a table that contain three distinct ones. So in hibernate enable debug (hibernate property or xml file) and take a look at the generated sql query. You can then run that query against your database, see the result and go from there. c) STS has really good support for the query api you are using in hibernate. If you use that IDE, you can directly paste the "from Table" query you have in the hibernate perspective and see the results there before you even run the code. Best regards, Alfredo On Sun, Mar 18, 2012 at 5:11 PM, nofear <[email protected]> wrote: > Hi guys , > > İ have a hibernate problem again, here's my problem , > I have an exam schedule table in my database and i inserted 3 rows of > data in this table. But when i try to get the data from database using > hibernate, just the first data comes. i mean , if there are 3 rows in > the table , so the FIRST ROW returns 3 times!. please help to fix this > issue. > > here's my code ; > > > SinavTakvim.java > *********************** > //ExamSchedule domain class > > > package tr.edu.gsu.yds.shared.domain; > > import java.io.Serializable; > > import javax.persistence.Column; > import javax.persistence.Entity; > import javax.persistence.Id; > import javax.persistence.Table; > > import net.sf.gilead.pojo.gwt.LightEntity; > > //ExamSchedule Domain > > @Entity > @Table(name = "sinavtakvim") > public class SinavTakvim extends LightEntity implements Serializable > { > private static final long serialVersionUID = 1L; > > private Integer sinavTakvimId; > private String sinavTarih; > private String sinavSinif; > private String sinavNot; > > @Id > @Column(name = "sinavTakvimId", nullable = false, length=10) > public Integer getSinavTakvimId() > { > return sinavTakvimId; > } > > public void setSinavTakvimId( Integer sinavTakvimId ) > { > this.sinavTakvimId = sinavTakvimId; > } > > @Column(name = "sinavTarihi", nullable = false, length=20) > public String getSinavTarihi() > { > return sinavTarih; > } > > public void setSinavTarihi( String sinavTarihi ) > { > this.sinavTarih = sinavTarihi; > } > > @Column(name = "sinavSinif", nullable = false, length=45) > public String getSinavSinif() > { > return sinavSinif; > } > > public void setSinavSinif( String sinavSinif ) > { > this.sinavSinif = sinavSinif; > } > > @Column(name = "sinavNot", length=45) > public String getSinavNot() > { > return sinavNot; > } > > public void setSinavNot( String sinavNot ) > { > this.sinavNot = sinavNot; > } > > } > > ------------------------------------------------------------- > > > > > SinavTakvimDao.java > ************************************ > package tr.edu.gsu.yds.server.dao; > > import java.util.List; > > import org.hibernate.Session; > import org.hibernate.Transaction; > > import tr.edu.gsu.yds.server.util.GileadHibernateUtil; > import tr.edu.gsu.yds.shared.domain.SinavTakvim; > > //ExamSchedule DAO > > public class SinavTakvimDao > { > public List<SinavTakvim> getSinavTakvimList() > { > Session session = null; > Transaction transaction = null; > try > { > session = > GileadHibernateUtil.getSessionFactory().openSession(); > transaction = session.beginTransaction(); > List<SinavTakvim> sinavTakvimList = > session.createQuery("from > SinavTakvim").list(); > transaction.commit(); > return sinavTakvimList; > } > catch ( RuntimeException e ) > { > transaction.rollback(); > throw e; > } > finally > { > if ( session != null ) > { > session.close(); > } > } > } > > > } > > ------------------------------------------------------------- > > > > > Here's i get the data from database and put the data into a celltable > ***************************************** > > > package tr.edu.gsu.yds.client.controller.ogrenci; > > import java.util.List; > > import tr.edu.gsu.yds.client.remote.YdsRemoteService; > import tr.edu.gsu.yds.client.remote.YdsRemoteServiceAsync; > import > tr.edu.gsu.yds.client.view.ogrenci.sinavislemleri.SinavTarihiGoruntuleme; > import tr.edu.gsu.yds.shared.domain.SinavTakvim; > > import com.google.gwt.core.client.GWT; > import com.google.gwt.event.dom.client.ClickEvent; > import com.google.gwt.event.dom.client.ClickHandler; > import com.google.gwt.user.client.Window; > import com.google.gwt.user.client.rpc.AsyncCallback; > > public class OgrenciSinavTarihiGoruntulemeController > { > private YdsRemoteServiceAsync ydsRemoteServiceAsync = > GWT.create( YdsRemoteService.class ); > private SinavTarihiGoruntuleme ogrenciSinavTarihiGoruntulemeSayfasi; > > > > > public > OgrenciSinavTarihiGoruntulemeController( SinavTarihiGoruntuleme > ogrenciSinavTarihiGoruntulemeSayfasi ) > { > this.ogrenciSinavTarihiGoruntulemeSayfasi = > ogrenciSinavTarihiGoruntulemeSayfasi; > > } > > public void send() > { > > > ydsRemoteServiceAsync.getSinavTakvimList( new > AsyncCallback<List<SinavTakvim>>() > { > public void onFailure( Throwable > caught ) > { > > Window.alert("Failure Error"); > } > > //Just Here , result returns > the "first row" 3 times , instead of all the 3 different rows. > public void onSuccess( > List<SinavTakvim> result ) > { > > if( result != null ) > { > > //Put the data > in to a celltable > > ogrenciSinavTarihiGoruntulemeSayfasi.getSinavTakvimCell().refresh( result > ); > > } > else > { > Window.alert( " No > exam found! " ); > > } > } > > } ); > > > > > ogrenciSinavTarihiGoruntulemeSayfasi.getOkeyButton().addClickHandler( new > ClickHandler() > { > > @Override > public void onClick( ClickEvent event ) > { > String date = > > ogrenciSinavTarihiGoruntulemeSayfasi.getSinavTarihWidget().getSelectedDate().toString(); > Window.alert( date ); > > } > } ); > > > } > > } > > -- > You received this message because you are subscribed to the Google Groups > "Google Web Toolkit" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/google-web-toolkit?hl=en. > > -- Alfredo Quiroga-Villamil AOL/Yahoo/Gmail/MSN IM: lawwton -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
