java - javax.persistence.PersistenceException: Unable to locate persistence units -


i had maven project, converted jpa project works maven. persistence.xml follows:

<?xml version="1.0" encoding="utf-8"?> <persistence version="2.1" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">     <persistence-unit name="my-pu" transaction-type="resource_local">         <description>my persistence unit</description>         <provider>org.hibernate.ejb.hibernatepersistence</provider>         <class>model.entity.tweet</class>         <class>model.entity.tweethashtag</class>         <class>model.entity.tweeturl</class>         <class>model.entity.user</class>         <exclude-unlisted-classes>true</exclude-unlisted-classes>         <properties>             <property name="hibernate.dialect" value="org.hibernate.dialect.mysqldialect"/>             <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.driver"/>             <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/tweetdb"/>             <property name="hibernate.connection.username" value="root"/>             <property name="hibernate.connection.password" value="root"/>             <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/tweetdb"/>             <property name="javax.persistence.jdbc.user" value="root"/>             <property name="javax.persistence.jdbc.password" value=""/>             <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.driver"/>         </properties>     </persistence-unit> </persistence> 

and have following entities:

package model.entity;   @entity @table(name="tweets")  public class tweet implements serializable{      private static final long serialversionuid = -1041037108182045708l;     @id     @column(name="tweet_id")     private int tweetid;      @column(name="tweet_text")     private string tweettext;      @temporal(temporaltype.timestamp)     @column(name = "created_at", nullable = false, length = 19)     private date createdat;      @column(name="lang_code")     private string languagecode;      @manytoone(optional=false)     @joincolumn(name = "user_id",referencedcolumnname="user_id")     private user user;      @onetomany(mappedby="tweet")     private set<tweethashtag> hashtags=new hashset<tweethashtag>(0);      @onetomany(mappedby="tweet")     private set<tweeturl> links=new hashset<tweeturl>(0);      public int gettweetid() {         return tweetid;     }      public void settweetid(int tweetid) {         this.tweetid = tweetid;     }      public string gettweettext() {         return tweettext;     }      public void settweettext(string tweettext) {         this.tweettext = tweettext;     }      public date getcreatedat() {         return createdat;     }      public void setcreatedat(date createdat) {         this.createdat = createdat;     }      public string getlanguagecode() {         return languagecode;     }      public void setlanguagecode(string languagecode) {         this.languagecode = languagecode;     }      public user getuser() {         return user;     }      public void setuser(user user) {         this.user = user;     }      public set<tweethashtag> gethashtags() {         return hashtags;     }      public void sethashtags(set<tweethashtag> hashtags) {         this.hashtags = hashtags;     }      public set<tweeturl> getlinks() {         return links;     }      public void setlinks(set<tweeturl> links) {         this.links = links;     }  } //////////////////////////////////    package model.entity;  @entity @table(name="tweet_hashtag") public class tweethashtag implements serializable{      /**      *       */     private static final long serialversionuid = 6302465277669302540l;      @id @generatedvalue     @column(name="hashtag_id")     private int hastagid;      public int gethastagid() {         return hastagid;     }      public void sethastagid(int hastagid) {         this.hastagid = hastagid;     }      @manytoone     @joincolumn(name = "tweet_id",referencedcolumnname="tweet_id")     private tweet tweet;      @column(name="hashtag")     private string hashtag;      public tweet gettweet() {         return tweet;     }      public void settweet(tweet tweet) {         this.tweet = tweet;     }      public string gethashtag() {         return hashtag;     }      public void sethashtag(string hashtag) {         this.hashtag = hashtag;     }  }  package model.entity; ///////////////////////////////////////  @entity @table(name="tweet_urls") public class tweeturl implements serializable{      /**      *       */     private static final long serialversionuid = -606690240421717136l;      @id @generatedvalue     @column(name="url_id")     private int urlid;      public int geturlid() {         return urlid;     }      public void seturlid(int urlid) {         this.urlid = urlid;     }      @manytoone     @joincolumn(name="tweet_id",referencedcolumnname="tweet_id")     private tweet tweet;      @column(name="url")     private string url;      public tweet gettweet() {         return tweet;     }      public void settweet(tweet tweet) {         this.tweet = tweet;     }      public string geturl() {         return url;     }      public void seturl(string url) {         this.url = url;     }    } //////////////////////////// package model.entity;  @entity @table(name="users")  public class user implements serializable{      @id     @column(name="user_id")     private int userid;      @column(name="screen_name")     private string screenname;      @column(name="profile_image_url")     private string profileimageurl;      @column(name="statuses_count")     private int statusescount;      @onetomany(mappedby="user")     private list<tweet> tweets;      public int getuserid() {         return userid;     }      public void setuserid(int userid) {         this.userid = userid;     }      public string getscreenname() {         return screenname;     }      public void setscreenname(string screenname) {         this.screenname = screenname;     }      public string getprofileimageurl() {         return profileimageurl;     }      public void setprofileimageurl(string profileimageurl) {         this.profileimageurl = profileimageurl;     }      public int getstatusescount() {         return statusescount;     }      public void setstatusescount(int statusescount) {         this.statusescount = statusescount;     }      public list<tweet> gettweets() {         return tweets;     }      public void settweets(list<tweet> tweets) {         this.tweets = tweets;     }  }  ////////////////// 

and error occures:

package model;  public class tweetpersistent {      private entitymanagerfactory emf;      private entitymanager em;       public void persist(pair<string, queryresult> pair)     {         list<status> tweets = pair.getvalue().gettweets();         (status tweet : tweets) {             this.inserttodb(pair.getkey(),tweet);             // or  this.batchinserttodb(pair.getkey(),tweet);          }      }      private void inserttodb(string key, status tweet) {         emf=persistence.createentitymanagerfactory("twitterqueryapp");         em=emf.createentitymanager();         em.gettransaction().begin();         em.persist(new pair<string,status>(key,tweet));         em.gettransaction().commit();   // insert code here       }      private void batchinserttodb(string key, status tweet) {         // insert batch               }  }  /////////// 

now error: javax.persistence.persistenceexception: unable locate persistence units

picked java_tool_options: -javaagent:/usr/share/java/jayatanaag.jar  log4j:warn no appenders found logger (twitter4j.httpclientimpl). log4j:warn please initialize log4j system properly. log4j:warn see http://logging.apache.org/log4j/1.2/faq.html#noconfig more info. exception in thread "thread-1" javax.persistence.persistenceexception: unable locate persistence units     @ org.hibernate.jpa.hibernatepersistenceprovider.getentitymanagerfactorybuilderornull(hibernatepersistenceprovider.java:101)     @ org.hibernate.jpa.hibernatepersistenceprovider.getentitymanagerfactorybuilderornull(hibernatepersistenceprovider.java:88)     @ org.hibernate.jpa.hibernatepersistenceprovider.createentitymanagerfactory(hibernatepersistenceprovider.java:69)     @ javax.persistence.persistence.createentitymanagerfactory(persistence.java:79)     @ javax.persistence.persistence.createentitymanagerfactory(persistence.java:54)     @ model.tweetpersistent.inserttodb(tweetpersistent.java:32)     @ model.tweetpersistent.persist(tweetpersistent.java:24)     @ controller.twitterstreamconsumer.run(twitterstreamconsumer.java:25)     @ java.lang.thread.run(thread.java:745) caused by: javax.persistence.persistenceexception: invalid persistence.xml. error parsing xml [line : -1, column : -1] : cvc-elt.1: deklaration des elements "persistence" kann nicht gefunden werden.     @ org.hibernate.jpa.boot.internal.persistencexmlparser.validate(persistencexmlparser.java:377)     @ org.hibernate.jpa.boot.internal.persistencexmlparser.loadurl(persistencexmlparser.java:310)     @ org.hibernate.jpa.boot.internal.persistencexmlparser.parsepersistencexml(persistencexmlparser.java:114)     @ org.hibernate.jpa.boot.internal.persistencexmlparser.doresolve(persistencexmlparser.java:104)     @ org.hibernate.jpa.boot.internal.persistencexmlparser.locatepersistenceunits(persistencexmlparser.java:86)     @ org.hibernate.jpa.hibernatepersistenceprovider.getentitymanagerfactorybuilderornull(hibernatepersistenceprovider.java:97)     ... 8 more 

i included different jars: hibernate-validation,java-persistence,hibernate-jpa , hibernate-entitymanager in build path , class path of project itself. copied persistence.xml in resource folder. did lots of things not work, same error.

thank in advance suggestions.

this looks problem xml schema jpa 2.1 version.

try , solution hope works you: how specify jpa 2.1 in persistence.xml?


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -