2012-09-11 3 views
0

최대 절전 모드를 사용하여 내 postgresql 데이터베이스에 삽입하고 싶습니다. 왜이 오류가 계속 발생하는지 파악하지 못했습니다. 최대 절전 모드로 데이터베이스 테이블과 열을 만들도록해야합니다. 생성 된 테이블에 삽입하십시오. 그래서 내 첫 번째 오류는 내가 지금이 내 오류가있는 새로운 오류가 팝업 응용 프로그램을 다시 실행 그러나 후에, 나는 이미 내 최대 절전 모드 라이브러리에 추가 된 SLF4J입니다 누락 된 jar 파일에 관한 것입니다 :Java 최대 절전 모드 오류

90 [main] INFO org.hibernate.annotations.common.Version - Hibernate Commons 

Annotations 3.2.0.Final 
100 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.6.10.Final 
100 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found 
100 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist 
100 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling 
150 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml 
150 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml 
Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xml not found 
    at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:170) 
    at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:2176) 
    at org.hibernate.cfg.Configuration.configure(Configuration.java:2157) 
    at org.hibernate.cfg.Configuration.configure(Configuration.java:2137) 
    at org.hibernate_main.HibernateMain.main(HibernateMain.java:13) 

이 있습니다 내 (최대 절전 모드 라이브러리 int)를 JAR 파일 :

hibernate3.jar 
antlr-2.7.6.jar 
commons-collections-3.1.jar 
dom4j-1.6.1.jar 
javassist-3.12.0.GA.jar 
jta-1.1.jar 
slf4j-api-1.6.1.jar 
hibernate-jpa-2.0-api-1.0.1.Final.jar 
postgresql-9.1-902.jdbc4 

그리고 내 코드 : 구성 (XML)

<?xml version="1.0" encoding="UTF-8"?> 

<!-- ~ Hibernate, Relational Persistence for Idiomatic Java ~ ~ Copyright (c) 2010, Red Hat Inc. or third-party contributors as ~ indicated by the @author tags or express copyright attribution ~ statements applied by the authors. All third-party contributions are ~ distributed under license by Red Hat Inc. ~ ~ This copyrighted material is made available to anyone wishing to use, modify, ~ copy, or redistribute it subject to the terms and conditions of the GNU ~ Lesser General Public License, as published by the Free Software Foundation. ~ ~ This program is distributed in the hope that it will be useful, ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License ~ for more details. ~ ~ You should have received a copy of the GNU Lesser General Public License ~ along with this distribution; if not, write to: ~ Free Software Foundation, Inc. ~ 51 Franklin Street, Fifth Floor ~ Boston, MA 02110-1301 USA --> 

<!DOCTYPE hibernate-configuration SYSTEM "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd" PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"> 
-<hibernate-configuration> -<session-factory> 
<!-- Database connection settings --> 
<property name="connection.driver_class">org.postgresql.Driver</property> 
<property name="connection.url">jdbc:postgresql://localhost:5432:MYPOS</property> 
<property name="connection.username">postgres</property> 
<property name="connection.password"/>perbert101 
<!-- JDBC connection pool (use the built-in) --> 
<property name="connection.pool_size">1</property> 
<!-- SQL dialect --> 
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</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">create</property> 
<!-- Names the annotated entity class --> 
<mapping class="org.user_detail.dto.UserDetail"/> </session-factory> </hibernate-configuration> 

UserDetail 등급 :

package org.user_detail.dto; 
import javax.persistence.Entity; 
import javax.persistence.Id; 

@Entity 
public class UserDetail { 
    @Id 
    private int userId; 
    private String userName; 

    public int getUserId() { 
     return userId; 
    } 
    public void setUserId(int userId) { 
     this.userId = userId; 
    } 
    public String getUserName() { 
     return userName; 
    } 
    public void setUserName(String userName) { 
     this.userName = userName; 
    } 

} 

내 주요 클래스 :

package org.hibernate_main; 
import org.hibernate.Session; 
import org.hibernate.SessionFactory; 
import org.hibernate.cfg.Configuration; 
import org.user_detail.dto.UserDetail; 

public class HibernateMain { 
    public static void main(String[] args){ 
     UserDetail user = new UserDetail(); 
     user.setUserId(1); 
     user.setUserName("Jerome"); 

     SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); 
     Session session = sessionFactory.openSession(); 
     session.beginTransaction(); 
     session.save(user); 
     session.getTransaction().commit(); 
    } 
} 

얘들이 오류가 무엇인지하고이를 해결하는 방법을 방법과 XML의 데이터베이스 연결이 성공 또는 실패한 경우 테스트 말해 줄 수 있습니다. 고마워.

+1

이 경우 설정 파일입니다 위의 코드에서

return new Configuration().configure("/path/to/hibernate.cfg.xml").buildSessionFactory(); 

:

당신은 또한에 지정할 수 있습니다? 불필요한 정보를 편집 해 주실 수 있습니까? –

답변

2

나는

/hibernate.cfg.xml not found 

이 충분히 명확하다고 생각합니다.

CLASSPATH에 있는지 확인하십시오.

+0

예 감사합니다. 내 실수 : 나는 최대 절전 모드에 있어야 이름 구성입니다. – Zyrax

+0

이 오류는 무엇을 의미합니까 구성을 구문 분석 할 수 없습니다 : /hibernate.cfg.xml – Zyrax

+0

그것은 오류가 있기 때문에 XML 파일을 읽을 수 없음을 의미합니다. "-"여기에는'- '과'- '와' perbert101'에는 닫는 태그가 없습니다. –