Tolong pilih kategori sesuai, jenis posting (diskusi atau bukan) dan sertakan tag/topik yang sesuai seperti komputer, java, php, mysql, dll. Promosi atau posting tidak pada tempatnya akan kami hapus!
- Bagi Anda yang ingin mendaftar, baca link berikut:
http://diskusiweb.com/discussion/50491/how-to-registrasi-diskusiweb-com-baca-ini-terlebih-dahulu
- Cara menyisipkan kode program supaya tampil rapi dan terformat dengan baik di diskusiweb.com: http://www.diskusiweb.com/discussion/50415/cara-menyisipkan-kode-program-di-diskusiweb-com
- Cara posting gambar/image di post Anda: http://www.diskusiweb.com/discussion/47345/cara-menyisipkan-menyertakan-image-pada-posting/p1

Bisa gak Ireport koneksinya menggunakan hibernate

Bisa tidak ireport menggunakan koneksi dgn hibernate
saya dpt kode spt ini, lalu saya ingin coba buat laporanya menggunkan ireport. tetapi setelah di coba error

file hibernate.cfg.xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/a6</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">none</property>

<mapping class="net.roseindia.Employee"/>

</session-factory>
</hibernate-configuration>


file HibernateUtil.java
package net.roseindia;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory from hibernate.cfg.xml
sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}

public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}




file Employee.java
package net.roseindia;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "employee")
public class Employee implements Serializable {
public Employee() {

}
@Id
@Column(name = "id")
Integer id;

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

public Integer getId() {
return id;
}

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

public String getName() {
return name;
}

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

}


file Example1.java
package net.roseindia;

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

public class Example1 {

/**
* @param args
*/
public static void main(String[] args) throws Exception {
/** Getting the Session Factory and session */
SessionFactory session = HibernateUtil.getSessionFactory();
Session sess = session.getCurrentSession();
/** Starting the Transaction */
Transaction tx = sess.beginTransaction();
/** Creating Pojo */
Employee pojo = new Employee();
pojo.setId(new Integer(5));
pojo.setName("XYZ");
/** Saving POJO */
sess.save(pojo);
/** Commiting the changes */
tx.commit();
System.out.println("Record Inserted");
/** Closing Session */
session.close();
}

}

di ireport
Tools -->Options-->Classpath-->Add folder -->saya masukan semua folder src dan lib
Tools-->Report Datasource -->New -->Hibernate Connection -->Next -->di Name ketik con-->saya klik Test
tampil error

An AnnotationConfiguration instance is required to use <mapping clazz="net.roseindia.Employee"/>

Apakah ada yg kurang dengan setingan saya, saya menggunakan ireport 3.0.

Comments

  • Originally posted by onsir
    di ireport
    Tools -->Options-->Classpath-->Add folder -->saya masukan semua folder src dan lib
    Tools-->Report Datasource -->New -->Hibernate Connection -->Next -->di Name ketik con-->saya klik Test
    tampil error

    An AnnotationConfiguration instance is required to use <mapping clazz="net.roseindia.Employee"/>

    Apakah ada yg kurang dengan setingan saya, saya menggunakan ireport 3.0.

    Mas, itu ndak salah itu clazz-nya pake Zzz.. bukan ss? Mungkin itu penyebab utamanya.. saya ndiri dulu pake iReport 2.0.4 & Hibernate 2, tp udah lama :)
Sign In or Register to comment.