获取以下错误org.hibernate.MappingException:没有JDBC类型的Dialect映射:-1

时间:2014-02-18 09:32:06

标签: java mysql hibernate jdbc mapping

我在查询时遇到异常。你能告诉mw我的代码中有什么错吗?

org.hibernate.MappingException: No Dialect mapping for JDBC type: -1
at org.hibernate.dialect.TypeNames.get(TypeNames.java:79)
at org.hibernate.dialect.TypeNames.get(TypeNames.java:104)
at org.hibernate.dialect.Dialect.getHibernateTypeName(Dialect.java:393)
at org.hibernate.loader.custom.CustomLoader$Metadata.getHibernateType(CustomLoader.java:582 
    at org.hibernate.loader.custom.CustomLoader$ScalarResultColumnProcessor.performDiscovery(Custom Loader.java:508)
    at org.hibernate.loader.custom.CustomLoader.autoDiscoverTypes(CustomLoader.java:524)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:1821)
    at org.hibernate.loader.Loader.doQuery(Loader.java:697)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
    at org.hibernate.loader.Loader.doList(Loader.java:2232)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129)
    at org.hibernate.loader.Loader.list(Loader.java:2124)
    at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:312)
    at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1723)
    at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165)
    at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:175)
    at com.bdisys.promorphics.dao.impl.BlogDaoImpl.getTopBlogsQuesByDate(BlogDaoImpl.java:126)
    at org.apache.jsp.Mydetails_jsp._jspService(Mydetails_jsp.java:935)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)
    at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
    at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
    at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:381)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at        org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
    at java.lang.Thread.run(Unknown Source)

Blog.java:

@SuppressWarnings("serial")
    @Entity
    @Table(name="blog")
    public class Blog extends BaseDomain {

    @Column(name="blog_title")
    private String blogTitle;

    @Column(name="blog_text",columnDefinition="TEXT")
    private String blogText;

    @Enumerated(EnumType.STRING)
    @Column(name="blog_status")
    private Status blogStatus; 

    @OneToOne
    @JoinColumn(name="created_by", nullable=false)
    private User createdBy;

    @OneToOne
    @JoinColumn(name="blog_category", nullable=false)
    private BlogCategory blogCategory;

    @Temporal(TemporalType.DATE)
    @Column(name="created_date")
    private Date createdDate; 

    @Column(name="likes")
    private Long likes;

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

    @Column(name="youtube_link")
    private String youTubeLik;

    @Column(name="moderator_comment")
    private String moderatorComment;

    @Lob
    @Column(name="blog_description")
    private String blog_desc;

    @ManyToOne
    @JoinColumn(name="users")
    private User users;

    public User getUsers() {
    return users;
    }

    public void setUsers(User users) {
     this.users = users;
    }

    public String getBlog_desc() {
    return blog_desc;
    }

    public void setBlog_desc(String blog_desc) {
    this.blog_desc = blog_desc;
    }

    public String getBlogTitle() {
    return blogTitle;
    }

    public void setBlogTitle(String blogTitle) {
    this.blogTitle = blogTitle;
    }

    public String getBlogText() {
    return blogText;
    }

    public void setBlogText(String blogText) {
    this.blogText = blogText;
    }

    public Status getBlogStatus() {
    return blogStatus;
    }

    public void setBlogStatus(Status blogStatus) {
    this.blogStatus = blogStatus;
    }

    public User getCreatedBy() {
    return createdBy;
    }

    public void setCreatedBy(User createdBy) {
    this.createdBy = createdBy;
    }

    public BlogCategory getBlogCategory() {
    return blogCategory;
    }

    public void setBlogCategory(BlogCategory blogCategory) {
    this.blogCategory = blogCategory;
    }

    public Date getCreatedDate() {
    return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
    this.createdDate = createdDate;
    }

    public Long getLikes() {
    return likes;
    }

    public void setLikes(Long likes) {
    this.likes = likes;
    }

    public String getUploads() {
    return uploads;
    }

    public void setUploads(String uploads) {
    this.uploads = uploads;
    }

    public String getYouTubeLik() {
    return youTubeLik;
    }

    public void setYouTubeLik(String youTubeLik) {
    this.youTubeLik = youTubeLik;
    }

    public String getModeratorComment() {
    return moderatorComment;
    }

    public void setModeratorComment(String moderatorComment) {
    this.moderatorComment = moderatorComment;
    }



    }

Askquestions.java:

 @SuppressWarnings("serial")
    @Entity
     @Table(name="askquestions")
    public class Askquestions extends BaseDomain {  

@Column(length = 100, name = "id_subscribers")
private String idSubscribers;

@Column(length = 100, name = "is_anonymous")
private String isAnonymous;

@Column(length = 100, name = "display_name")
private String displayName;

@Temporal(TemporalType.DATE)
    @Column(length = 100, name = "created_on")
private Date createdQuesOn;

@Lob
@Column(name = "ask_question")
private String askQuestion;

@Column(length = 100, name = "ask_to_whom")
private String askToWhom;

@Lob
@Column(name="question_of_day")
private String questionOfDay;

@ManyToOne
 @JoinColumn(name="ask_category")
 private Askcategory askcategory;

 @ManyToOne
    @JoinColumn(name="users")
    private User users;

public User getUsers() {
    return users;
}

public void setUsers(User users) {
    this.users = users;
}


public Askcategory getAskcategory() {
    return askcategory;
}

public void setAskcategory(Askcategory askcategory) {
    this.askcategory = askcategory;
}

public String getQuestionOfDay() {
        return questionOfDay;
    }

    public void setQuestionOfDay(String questionOfDay) {
        this.questionOfDay = questionOfDay;
    }

public String getIdSubscribers() {
    return idSubscribers;
}

public void setIdSubscribers(String idSubscribers) {
    this.idSubscribers = idSubscribers;
}

public String getIsAnonymous() {
    return isAnonymous;
}

public void setIsAnonymous(String isAnonymous) {
    this.isAnonymous = isAnonymous;
}

public String getDisplayName() {
    return displayName;
}

public void setDisplayName(String displayName) {
    this.displayName = displayName;
}

public String getAskQuestion() {
    return askQuestion;
}

public void setAskQuestion(String askQuestion) {
    this.askQuestion = askQuestion;
}

public String getAskToWhom() {
    return askToWhom;
}

public void setAskToWhom(String askToWhom) {
    this.askToWhom = askToWhom;
}

public Date getCreatedQuesOn() {
    return createdQuesOn;
}

public void setCreatedQuesOn(Date createdQuesOn) {
    this.createdQuesOn = createdQuesOn;
}


    } 

BlogDaoimpl方法:当其他小查询被执行时,此查询没有被执行。为什么会发生????

     String sql = "  select title , date from (select blog_title as title ,created_date          as date from  blog  union select ask_question as title , created_on as date from askquestions ) as aa order by date desc";

   SQLQuery query = getSession().createSQLQuery(sql);

    return query.list();

hibrnate.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>
    <property name="hibernate.connection.driver_class">
        com.mysql.jdbc.Driver
    </property>
  <!-- <property name="hibernate.connection.password">websitebdi</property>
    <property    name="hibernate.connection.url">jdbc:mysql://184.172.182.251:3306/bdiwebsite</property>
    <property name="hibernate.connection.username">bdiwebsite</property>  -->

    <property name="hibernate.connection.password">MAYbdiSYS2008</property>
    <property name="hibernate.connection.url">jdbc:mysql://115.119.114.10:3306/bdisystems</property>
    <property name="hibernate.connection.username">admin</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="current_session_context_class">thread</property>
    <property name="hibernate.hbm2ddl.auto">update</property>
    <property name="hibernate.show_sql">false</property>
    <property name="format_sql">true</property>
    <property name="use_sql_comments">true</property>


    <property name="hibernate.connection.provider_class">
        org.hibernate.connection.C3P0ConnectionProvider
    </property>
    <!--  The maximum number of connections  -->
    <property name="hibernate.c3p0.max_size">20</property>
    <!--  The minimum number of connections  -->
    <property name="hibernate.c3p0.min_size">5</property>
    <!--  Get a connection timeout  , If you exceed this time  , Throws an exception, in milliseconds  -->
    <property name="hibernate.c3p0.timeout">120</property>
    <!--  The maximum number of PreparedStatement  -->
    <property name="hibernate.c3p0.max_statements">100</property>
    <!--  Every 120 seconds checking connection idle connection in the pool, the unit is in seconds  -->
    <property name="hibernate.c3p0.idle_test_period">120</property>
    <!--  When connection pooling connections inside out, look at the new C3P0     get the number of connections  -->
    <property name="hibernate.c3p0.acquire_increment">2</property>
    <!--  Always verify the connection  -->
    <property name="hibernate.c3p0.validate">true</property>
    <!--    
        <property name="hibernate.c3p0.max_size">100</property>
        <property name="hibernate.c3p0.min_size">0</property>
        <property name="hibernate.c3p0.acquire_increment">1</property>
        <property name="hibernate.c3p0.idle_test_period">300</property>
        <property name="hibernate.c3p0.max_statements">0</property>
        <property name="hibernate.c3p0.timeout">100</property>
    -->

    <!-- Mapping Classes -->

    <mapping class="com.bdisys.promorphics.domain.BlogCategory"/>
    <mapping class="com.bdisys.promorphics.domain.Blog"/>

    <mapping class="com.bdisys.promorphics.domain.Career"/>
    <mapping class="com.bdisys.promorphics.domain.Partners"/>
    <mapping class="com.bdisys.promorphics.domain.Askcategory"/>
    <mapping class="com.bdisys.promorphics.domain.Askquestions"/>
    <mapping class="com.bdisys.promorphics.domain.Askanswers"/>

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

1 个答案:

答案 0 :(得分:0)

创建自定义Dialect(扩展MySQLDialect)并在构造函数中添加

registerHibernateType(Types.LONGVARCHAR, TextType.INSTANCE.getName());

public class MySQLDialect extends MySQLDialect {
  public AGOSQLServerDialect() {
    super();
    registerHibernateType(Types.LONGVARCHAR, TextType.INSTANCE.getName());
  }
}

请记住将方言类更改为Hibernate配置文件

<property name="hibernate.dialect">path.to.YourDialect</property>