2013-01-24 17 views
8

chúng tôi đang tích hợp java blazeds hibernate với dự án flex .. Đầu tiên chúng tôi kiểm tra java hibernate tinh khiết trong nhật thực và nó đang thực hiện tốt. Nhưng khi chúng tôi đặt cùng trong tomcat cho hội nhập flex với blazeds nó được hiển thị các lỗi sau đây.Đây là lỗi duy nhất.tài sản hibernate không tìm thấy

Jan 24, 2013 11:31:31 AM org.hibernate.cfg.Environment <clinit> 
INFO: Hibernate 3.2.6 
Jan 24, 2013 11:31:31 AM org.hibernate.cfg.Environment <clinit> 
INFO: hibernate.properties not found 
Jan 24, 2013 11:31:31 AM org.hibernate.cfg.Environment buildBytecodeProvider 
INFO: Bytecode provider name : cglib 
Jan 24, 2013 11:31:31 AM org.hibernate.cfg.Environment <clinit> 
INFO: using JDK 1.4 java.sql.Timestamp handling 
Jan 24, 2013 11:31:31 AM org.hibernate.cfg.Configuration configure 
INFO: configuring from resource: /hibernate.cfg.xml 
Jan 24, 2013 11:31:31 AM org.hibernate.cfg.Configuration getConfigurationInputSt 
ream 
INFO: Configuration resource: /hibernate.cfg.xml 

đây là hibernate.cfg.xml (Để xác định xem hibernate.cfg.xml không được tìm thấy và tôi đã thử nghiệm bằng cách xóa DOCTYPE của .cfg.xml sau đó sản lượng tomcat hiển thị đã nói rằng phần tử gốc chưa được tìm thấy. đồi khế, đồi có nghĩa là nó có khả năng tìm ra hibernate.cfg.xml (tôi nghĩ)

<?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> 
     <property name="connection.url">jdbc:mysql://localhost/test</property> 
     <property name="connection.username">root</property> 
     <property name="connection.password">root</property> 
     <property name="connection.driver_class">com.mysql.jdbc.Driver</property> 
     <property name="dialect">org.hibernate.dialect.MySQLDialect</property> 

     <property name="show_sql">true</property> 

     <property name="format_sql">true</property> 

     <!-- JDBC connection pool (use the built-in) --> 
     <property name="connection.pool_size">1</property> 

     <property name="current_session_context_class">thread</property> 
     <mapping class="com.model.User" /> 
     <mapping class="com.model.UserDetails" /> 
     <mapping class="com.model.LoanDetails" /> 
     <mapping class="com.model.BorrowerDetails" /> 

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

đây là hiberutil.java

public class HibernateUtil 
{ 



    private static SessionFactory sessionFactory=configureSessionFactory(); 
    private static ServiceRegistry serviceRegistry; 


    private static SessionFactory configureSessionFactory() throws HibernateException { 
     Configuration configuration = new Configuration(); 
     configuration.configure(); 
     serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();   
     sessionFactory = configuration.buildSessionFactory(serviceRegistry); 
     return sessionFactory; 
    } 
    public static SessionFactory getSessionFactory() 
    { 
     return sessionFactory; 
    } 
} 

tại sao lỗi được hiển thị? kiểm soát đến từ flex bên và thực hiện điểm bắt đầu của phương thức java ... nhưng khi nói đến việc thực thi công cụ ngủ đông, nó hiển thị lỗi này trong tomcat ...

Nhưng khi tôi thực thi java + hibernate như một ứng dụng thuần túy java, nó đang thực hiện tốt.

ai cũng có thể giúp tôi?

Cảm ơn

EDIT 1 Sau khi sửa đổi được đề xuất bởi @Andremoniy và đặt .cfg.xml trong thư mục src và đây cũng trong eclipse nó đang làm việc nhưng không phải trong tomcat với flex

lỗi sau đến

org.hibernate.MappingException: An AnnotationConfiguration instance is required 
to use <mapping class="com.model.User"/> 
     at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.jav 
a:1606) 
     at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.jav 
a:1561) 
     at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1540) 
     at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1514) 
     at org.hibernate.cfg.Configuration.configure(Configuration.java:1434) 
     at org.hibernate.cfg.Configuration.configure(Configuration.java:1420) 
     at com.sample.HibernateUtil.configureSessionFactory(HibernateUtil 
.java:26) 
     at com.sample.HibernateUtil.<clinit>(HibernateUtil.java:20) 
     at com.sample.App.checkUser(App.java:34) 
+1

Xin chào, lỗi trong câu hỏi ban đầu của bạn là gì? Trong ngăn xếp bạn đã dán, tôi chỉ có thể thấy 'hibernate.properties not found', đây không phải là lỗi. –

+0

Trong câu hỏi origional của tôi thực hiện dừng lại bằng cách in ngăn xếp tôi dán và sau đó không thực hiện truy vấn và không có đầu ra .. nó kết thúc như thế này ... i đặt show_sql là đúng nhưng đó không phải là in .. –

+0

Bạn đã kiểm tra kết nối với cơ sở dữ liệu của bạn? –

Trả lời

1

Tôi đoán vấn đề là với mã cho cấu hình bạn đã đề cập cho .hbm.xml có thể không hoạt động trong Tomcat.

Tôi nghĩ rằng nó cần đối tượng AnnotationConfiguration. Tôi đoán bạn đã sử dụng mã này do việc tạo đối tượng Annotationconfiguration không hoạt động.

Tạo tốt hơn dự án hibernate với mớ và xuất tệp war sang Tomcat (với thay đổi là Annotationconfiguration). Cũng sử dụng jar log4j để hiển thị chi tiết về việc thực thi Tomcat với các đầu ra gỡ lỗi, do đó đầu ra Tomcat sẽ in tất cả luồng thực thi.

1

Dường như với tôi, bạn có thể giải quyết vấn đề này, bằng cách chuyển hibernate.cfg.xml trực tiếp vào Configuration.

try (InputStream in = HibernateUtil.class.getResourceAsStream("/hibernate.cfg.xml")) { 
    Configuration configuration = new Configuration().addInputStream(in).configure(); 
... 
} ... 

Điều duy nhất, bạn phải trỏ đúng đường dẫn hoặc lớp học, cho getResourceAsStream. Hoặc bạn có thể muốn tạo InputStream bằng cách sử dụng một số đường dẫn tương đối.

+0

cảm ơn. nhưng getClass() là lỗi trỏ. –

+0

Thực ra, đây là ví dụ phổ biến Tôi đã đổi nó thành 'HibernateUtil.class', nhưng thực sự điều này phụ thuộc vào ** where ** your hibernate.cfg.xml' đặt vào gói nơi 'HibernateUtil.java' được đặt. – Andremoniy

+0

@SamprityKashyap Bạn đã đặt tập tin' hibernate.cfg.xml' ở đâu? – Andremoniy

0

nếu nó được xuất hiện mà bạn sử dụng IntelliJ IDEA bạn cần phải đặt hibernate.cfg.xml file vào nguồn thư mục

ads

một d nếu bạn sẽ có sau khi lỗi tiếp theo: org.hibernate.service.jndi.JndiException: Lỗi phân tích cú pháp tên JNDI []

xóa trong tên file hibernate.cfg.xml của thẻ xem hình:

enter image description here