Sunday, May 28, 2017

apache shindig java maven compile success log



2015/10/23 - Apache Shindig has been retired. For more information please explore the Attic.

apache shindig java maven compile success log

1. get apache shindig 2.5.2 latest
http://archive.apache.org/dist/shindig/2.5.2/shindig-2.5.2-source.zip

2. how to compiler shindig-2.5.2-source

unzip this source.

edit shindig-2.5.2-source\pom.xml, comment below code:
<!--
    <repository>
      <id>diff_match_patch</id>
      <url>http://google-diff-match-patch.googlecode.com/svn/trunk/maven</url>
    </repository>
    <repository>
      <id>caja</id>
      <url>http://google-caja.googlecode.com/svn/maven</url>
    </repository>
    <repository>
      <id>oauth</id>
      <url>http://oauth.googlecode.com/svn/code/maven</url>
    </repository>
    -->

and change:
<groupId>diff_match_patch</groupId>
<artifactId>diff_match_patch</artifactId>
to:
<groupId>org.webjars</groupId>
<artifactId>google-diff-match-patch</artifactId>

edit shindig-2.5.2-source\features\pom.xml, comment below code:
<!--
  <pluginRepositories>
    <pluginRepository>
      <id>jsdoctk2</id>
      <url>http://jsdoctk-plugin.googlecode.com/svn/repo</url>
    </pluginRepository>
  </pluginRepositories>
-->

edit shindig-2.5.2-source\java\gadgets\pom.xml,change:
<groupId>diff_match_patch</groupId>
<artifactId>diff_match_patch</artifactId>
to:
<groupId>org.webjars</groupId>
<artifactId>google-diff-match-patch</artifactId>

3. compile
> mvn package -Dmaven.test.skip=true

4. Last result
[INFO] --- maven-site-plugin:3.2:attach-descriptor (attach-descriptor) @ shindig-server ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Apache Shindig Project ............................. SUCCESS [  2.125 s]
[INFO] Apache Shindig Features ............................ SUCCESS [  5.049 s]
[INFO] Apache Shindig Common Code ......................... SUCCESS [  7.014 s]
[INFO] Apache Shindig Gadget Renderer ..................... SUCCESS [ 12.246 s]
[INFO] Apache Shindig Social API .......................... SUCCESS [  4.275 s]
[INFO] Apache Shindig Sample Container .................... SUCCESS [  1.981 s]
[INFO] Apache Shindig Sample Web App Maven Archetype ...... SUCCESS [ 11.330 s]
[INFO] Apache Shindig Web App Resources ................... SUCCESS [  3.129 s]
[INFO] Apache Shindig Extra Modules ....................... SUCCESS [  3.474 s]
[INFO] Apache Shindig Web App Dependencies ................ SUCCESS [  0.690 s]
[INFO] Apache Shindig Web App ............................. SUCCESS [  4.492 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 56.284 s
[INFO] Finished at: 2017-05-29T10:33:37+08:00
[INFO] Final Memory: 56M/817M

[INFO] ------------------------------------------------------------------------

5. Edit in eclipse(or Sts)

5.1 shindig-gadgets properties > Java Build Path: Delete src/test/java and src/test/resource

5.2 edit shindig-server/pom.xml:
<build>
  <plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <configuration>
           <!-- add below one row -->
          <failOnMissingWebXml>false</failOnMissingWebXml>
          ...

Sunday, May 21, 2017

com.netflix.client.ClientException: Load balancer does not have available server for client:

What:
Spring boot feignclient call other instance show below error:
com.netflix.client.ClientException: Load balancer does not have available server for client:

Why:
if eureka.client.fetchRegistry is false, the various shuffle methods in com.netflix.discovery.shared.Applications are not called and hence Applications.shuffleVirtualHostNameMap is never populated. This map is used later for look up in the method Applications.getInstancesByVirtualHostName that then fails.
How:
eureka:
  client:
    registerWithEureka: true
    fetchRegistry: true # change to true, is ok

Last:
Thanks

Friday, May 5, 2017

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: myzc_string_record is not mapped

What

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: myzc_string_record is not mapped
 at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:171) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
 at org.hibernate.hql.internal.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:91) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
 at org.hibernate.hql.internal.ast.tree.FromClause.addFromElement(FromClause.java:76) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
 at org.hibernate.hql.internal.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:321) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
 at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3687) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
 at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3576) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
 at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:716) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
 at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:572) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
 at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:309) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
 at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:257) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
 at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:262) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
 at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:190) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
 ... 58 common frames omitted


Why

Below is my old query sql. and i used it in spring boot jpa environment:
@Query(value = "select key_type,max(key_id) from myzc_string_record group by key_type")
 Map selectMaxKeyTypeAndId();

How
Below is my new query sql,add nativeQuery = true:
@Query(value = "select key_type,max(key_id) from myzc_string_record group by key_type", nativeQuery = true)
 Map selectMaxKeyTypeAndId();

Last
Thanks!

Caused by: java.lang.IllegalArgumentException: This class [class com.myzc98.server.domain.JsonRecordDomain] does not define an IdClass

Below is my error message:

Caused by: java.lang.IllegalArgumentException: This class [class com.myzc98.server.domain.JsonRecordDomain] does not define an IdClass
 at org.hibernate.jpa.internal.metamodel.AbstractIdentifiableType.getIdClassAttributes(AbstractIdentifiableType.java:183) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
 at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation$IdMetadata.(JpaMetamodelEntityInformation.java:253) ~[spring-data-jpa-1.11.1.RELEASE.jar:na]
 at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.(JpaMetamodelEntityInformation.java:84) ~[spring-data-jpa-1.11.1.RELEASE.jar:na]
 at org.springframework.data.jpa.repository.support.JpaEntityInformationSupport.getEntityInformation(JpaEntityInformationSupport.java:68) ~[spring-data-jpa-1.11.1.RELEASE.jar:na]
 at org.springframework.data.jpa.repository.support.SimpleJpaRepository.(SimpleJpaRepository.java:110) ~[spring-data-jpa-1.11.1.RELEASE.jar:na]
 at com.myzc98.server.mapper.MyMapperImpl.(MyMapperImpl.java:15) ~[classes/:na]
 at com.myzc98.server.mapper.MyMapperFactoryBean$CustomRepositoryFactory.getTargetRepository(MyMapperFactoryBean.java:38) ~[classes/:na]
 at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:199) ~[spring-data-commons-1.13.1.RELEASE.jar:na]
 at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:277) ~[spring-data-commons-1.13.1.RELEASE.jar:na]
 at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:263) ~[spring-data-commons-1.13.1.RELEASE.jar:na]
 at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:101) ~[spring-data-jpa-1.11.1.RELEASE.jar:na]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
 ... 30 common frames omitted

Why:
Because i used Composite Primary Key in JsonRecordDomain.

How to fixed it, add @IdClass composite annotation:

@Entity
@Table(name = "myzc_json_record")
@IdClass(String2LongId.class)
public class JsonRecordDomain implements java.io.Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 主键类型
     */
    @Id
    @Column(name = "key_type")
    private String keyType;

    /**
     * 主键类型 ID
     */
    @Id
    @Column(name = "key_id")
    private Long keyId;

    // ...
}

public class String2LongId implements Serializable {
 /**
  * 
  */
 private static final long serialVersionUID = 1L;
 
 @Column(nullable = false)
 private String keyType;

 @Column(nullable = true)
 private Long keyId;

 public String2LongId() {
 }

 public String2LongId(String keyType, Long keyId) {
  this.keyType = keyType;
  this.keyId = keyId;
 }

 public String getKeyType() {
  return keyType;
 }

 public void setKeyType(String keyType) {
  this.keyType = keyType;
 }

 public Long getKeyId() {
  return keyId;
 }

 public void setKeyId(Long keyId) {
  this.keyId = keyId;
 }

 @Override
 public int hashCode() {
  final int prime = 31;
  int result = 1;
  result = prime * result + ((keyType == null) ? 0 : keyType.hashCode());
  result = prime * result + ((keyId == null) ? 0 : keyId.hashCode());
  return result;
 }

 @Override
 public boolean equals(Object obj) {
  do{
   if (this == obj)
    return true;
   
   if (obj == null)
    break;
   
   if (!String2LongId.class.equals(obj.getClass()))
    break;
   
   String2LongId other = (String2LongId) obj;
   if (this.keyType == null) {
    if (other.keyType != null)
     break;
   }else if(!this.keyType.equals(other.keyType)){
    break;
   }
   
   if (this.keyId == null) {
    if (other.keyId != null)
     break;
   }else if(!this.keyId.equals(other.keyId)){
    break;
   }
   
   return true;
  }while(false);
  
  return false;
 }

 @Override
 public String toString() {
  return "String2LongId [keyType=" + keyType + ", keyId=" + keyId + "]";
 }
}