1 2 Previous Next 20 Replies Latest reply on Oct 8, 2013 5:40 PM by Jonathan Fuerth Go to original post
      • 15. Re: Errai JPA Failing To Compile
        Saif Rehman Newbie

        Hi Jon,

        I did this.

        -1) Created a new errai project. (a Test Project)

        -2) In the client.shared package , I pasted My @Entity classes one by one

        -3) And I found the following two classes are causing this

        java.lang.ClassCastException: org.jboss.errai.codegen.meta.impl.gwt.GWTTypeVariable cannot be cast to org.jboss.errai.codegen.meta.MetaClass

         

        Let me paste the code:

         

        TraderAccount.java

         

         

        package app.client.shared.datamodel;

         

        import java.util.Date;

        import java.util.HashSet;

        import java.util.LinkedList;

        import java.util.List;

        import java.util.Set;

         

        import javax.persistence.CascadeType;

        import javax.persistence.Column;

        import javax.persistence.Entity;

        import javax.persistence.FetchType;

        import javax.persistence.GeneratedValue;

        import javax.persistence.Id;

        import javax.persistence.JoinColumn;

        import javax.persistence.JoinTable;

        import javax.persistence.ManyToMany;

        import javax.persistence.ManyToOne;

        import javax.persistence.OneToMany;

        import javax.persistence.Table;

         

        import org.jboss.errai.common.client.api.annotations.Portable;

        import org.jboss.errai.databinding.client.api.Bindable;

         

        /**

        * Represents a MetaTrader account.

        */

        /**

        * @author Sana Shafqat

        *

        */

        @Portable @Bindable

        @Entity

        @Table(name = "trader_account")

        public class TraderAccount {

         

            @Id

            @GeneratedValue

            private Long id;

         

            @Column(nullable = false, unique = true)

            private String username;

           

            @Column(nullable = false)

            private String password;

           

            @Column(nullable = false)

            private String label;

           

            private boolean disabled = true;

           

             // An Enum

            private AccountType type = AccountType.DEMO;

           

            private String description;

           

            private String currency;

           

            private Boolean isVerified;

           

            private Boolean isDemo;

           

            private Date lastAttempt;

           

            private Boolean isConnectedBefore=false;

           

         

            @ManyToOne(optional = false)

            private Broker broker;

           

            @ManyToOne(optional = false, fetch = FetchType.LAZY)

            private User user;

           

            @OneToMany(cascade = {CascadeType.ALL})

            private List<TraderDataFeed> dataFeeds = new LinkedList<TraderDataFeed>();

           

           

            @ManyToMany(fetch = FetchType.LAZY, cascade=CascadeType.ALL)

            @JoinTable(name = "trader_account_symbols", joinColumns ={

                    @JoinColumn(name = "id", nullable=false)},

                    inverseJoinColumns ={ @JoinColumn (name="symbolId", nullable = false)}

            )

            private Set<Symbol> symbols=new HashSet<Symbol>(0);

           

            /**

             * Returns the entity ID which uniquely identifies persistent entities of this type. Will be {@code null} while the

             * object has not been persisted yet.

             * <p/>

             * Note that entity ID is mutable and should not be used as hash codes or for object equality comparison in

             * containers. Use object identity for that.

             *

             * @return the entity ID, or {@code null} for non-persistent entities.

             */

          

           

            /**

             * Returns the username of the MetaTrader account.

             *

             * @return the username of the MetaTrader account.

             */

            public String getUsername() {

                return username;

            }

         

            public Long getId() {

                return id;

            }

         

            public void setId(Long id) {

                this.id = id;

            }

         

            /**

             * Sets the username of the MetaTrader account.

             *

             * @param username the username of the MetaTrader account.

             */

            public void setUsername(String username) {

                this.username = username;

            }

         

            /**

             * Returns the password of the MetaTrader account.

             *

             * @return the password of the MetaTrader account.

             */

            public String getPassword() {

                return password;

            }

         

            /**

             * Sets the password of the MetaTrader account.

             *

             * @param password the password of the MetaTrader account.

             */

            public void setPassword(String password) {

                this.password = password;

            }

         

            public String getLabel() {

                return label;

            }

         

            public void setLabel(String label) {

                this.label = label;

            }

         

            /**

             * Returns the type of account.

             *

             * @return the type of account.

             */

            public AccountType getType() {

                return type;

            }

         

            /**

             * Sets the type of account.

             *

             * @param type the type of account.

             */

            public void setType(AccountType type) {

                this.type = type;

            }

         

            /**

             * Returns the users description of the account.

             *

             * @return the users description of the account.

             */

            public String getDescription() {

                return description;

            }

         

            /**

             * Sets the users description of the account.

             *

             * @param description the users description of the account.

             */

            public void setDescription(String description) {

                this.description = description;

            }

         

            /**

             * Returns the base currency of the account.

             *

             * @return the base currency of the account.

             */

            public String getCurrency() {

                return currency;

            }

         

            /**

             * Sets the base currency of the account.

             *

             * @param currency the base currency of the account.

             */

            public void setCurrency(String currency) {

                this.currency = currency;

            }

         

            public Boolean getIsVerified() {

                return isVerified;

            }

         

            public void setIsVerified(Boolean isVerified) {

                this.isVerified = isVerified;

            }

         

            public Boolean getIsDemo() {

                return isDemo;

            }

         

            public void setIsDemo(Boolean isDemo) {

                this.isDemo = isDemo;

            }

         

            public Broker getBroker() {

                return broker;

            }

         

            public void setBroker(Broker broker) {

                this.broker = broker;

            }

         

            public User getUser() {

                return user;

            }

         

            public void setUser(User user) {

                this.user = user;

            }

         

            public boolean isDisabled() {

                return disabled;

            }

         

            public void setDisabled(boolean disabled) {

                this.disabled = disabled;

            }

         

            public List<TraderDataFeed> getDataFeeds() {

                return dataFeeds;

            }

         

            public void setDataFeeds(List<TraderDataFeed> dataFeeds) {

                this.dataFeeds = dataFeeds;

            }

           

            public Set<Symbol> getSymbols() {

                return symbols;

            }

         

            public void setSymbols(Set<Symbol> symbols) {

                this.symbols = symbols;

            }

           

           

           

            public Date getLastAttempt() {

                return lastAttempt;

            }

         

            public void setLastAttempt(Date lastAttempt) {

                this.lastAttempt = lastAttempt;

            }

         

            public Boolean getIsConnectedBefore() {

                return isConnectedBefore;

            }

         

            public void setIsConnectedBefore(Boolean isConnectedBefore) {

                this.isConnectedBefore = isConnectedBefore;

            }

         

            public void copyFrom(TraderAccount ref){

                this.setLabel(ref.getLabel());

                this.setUsername(ref.getUsername());

                this.setPassword(ref.getPassword());

                this.setId(ref.getId());

                this.setBroker(ref.getBroker());

                this.setCurrency(ref.getCurrency());

                this.setDataFeeds(ref.getDataFeeds());

                this.setDescription(ref.getDescription());

                this.setDisabled(ref.disabled);

                this.setType(ref.getType());

                this.setUser(ref.getUser());

                this.setLastAttempt(ref.getLastAttempt());

            }

         

        }

         

        TraderDataFeed.java

         

         

        package app.client.shared.datamodel;

         

        import javax.persistence.Column;

        import javax.persistence.Entity;

        import javax.persistence.JoinColumn;

        import javax.persistence.ManyToOne;

        import javax.persistence.Table;

         

        import org.jboss.errai.common.client.api.annotations.Portable;

         

        import com.google.common.base.Preconditions;

         

        /**

        * Data feed that subscribes to updates on a ticket symbol on a MetaTrader account.

        */

        @Portable

        @Entity

        @Table(name = "trader_data_feed")

        public class TraderDataFeed extends DataFeed {

         

            @Column(nullable = false)

            private String symbol;   

         

            @ManyToOne(optional = false)

            private TraderAccount traderAccount;

         

            @ManyToOne(optional = true)

            @JoinColumn(name="STRATEGY_ID"/* nullable=false*/)

            private Strategy strategy;

           

            @Column(nullable = false)

            private Boolean latest;

         

            /**

             * Default constructor, used by JPA to load a persistent entity.

             */

            public TraderDataFeed() {

            }

         

            /**

             * Creates a new trader data feed and attaches it to the meta trader account.

             *

             * @param user              the user that owns the feed.

             * @param traderAccount the trader account which must be owned by the user.

             * @param symbol      the symbol to get updates for.

             */

            public TraderDataFeed(User user, TraderAccount traderAccount, String symbol) {

                Preconditions.checkArgument(traderAccount.getUser() == user);

         

                this.setUser(user);

                this.symbol = symbol;

                this.traderAccount = traderAccount;

            }

         

            /**

             * Returns the symbol to get updates for.

             *

             * @return the symbol to get updates for.

             */

            public String getSymbol() {

                return symbol;

            }

         

            /**

             * Sets the symbol to get updates for.

             *

             * @param symbol the symbol to get updates for.

             */

            public void setSymbol(String symbol) {

                this.symbol = symbol;

            }

         

            /**

             * Returns the TraderAccount to get updates from.

             *

             * @return the TraderAccount to get updates from.

             */

            public TraderAccount getTraderAccount() {

                return traderAccount;

            }

         

            /**

             * Sets the TraderAccount to get updates from.

             *

             * @param traderAccount the TraderAccount to get updates from.

             */

            public void setTraderAccount(TraderAccount traderAccount) {

                this.traderAccount = traderAccount;

            }

         

            public Strategy getStrategy() {

                return strategy;

            }

         

            public void setStrategy(Strategy strategy) {

                this.strategy = strategy;

            }

         

            /**

             *

             * @return

             */

            public Boolean getLatest() {

                return latest;

            }

         

            public void setLatest(Boolean latest) {

                this.latest = latest;

            }

             

        }

         

        Please Check these classes and let me know . What could be the problem .? I am also trying to figure it out.

         

        Thanks!

        • 16. Re: Errai JPA Failing To Compile
          Saif Rehman Newbie

          Alright!

           

          Jon,

          I guess there is a probelm in this part

          @Entity

          @Table(name = "trader_data_feed")

          public class TraderDataFeed extends DataFeed     // Inhereitance? is it supported?

           

          I changed it like this.....

          @Entity

          @Table(name = "trader_data_feed")

          public class TraderDataFeed

           

          And added an @Id column and the Exception is gone.

           

          Can you please give your advise on it?

           

          Thanks!

          • 17. Re: Errai JPA Failing To Compile
            Saif Rehman Newbie

            Oh! I forgot to mention.

            I also changed this.

            @Portable

            @Entity

            @Inheritance(strategy = InheritanceType.JOINED)

            @Table(name = "data_feed")

            public abstract class DataFeed {       // removed the abstract. Its causing exception.

             

            to

             

            @Portable

            @Entity

            @Inheritance(strategy = InheritanceType.JOINED)

            @Table(name = "data_feed")

            public class DataFeed {

            • 18. Re: Errai JPA Failing To Compile
              Jonathan Fuerth Master

              Hi Saif,

               

              Thanks for digging into this problem! Your findings are very useful.

               

              Entity inheritence is not tested in the current version of ErraiJPA, so it's unlikely to work. Obviously, it's something we should support (and it shouldn't be terribly hard to do--most of the work will be in writing the tests); we were really just waiting for somebody to request it.

               

              I'm surprised to see an abstract @Entity type cause the specific error you were encountering (java.lang.ClassCastException: org.jboss.errai.codegen.meta.impl.gwt.GWTTypeVariable cannot be cast to org.jboss.errai.codegen.meta.MetaClass) because that indicates that the code generator found a (Java generics) type variable where it expected a class. But if making DataFeed concrete solved the problem, who am I to argue with the facts?

               

              Would you please file a JIRA for this issue? I want to be sure we don't lose track of both the issue and your findings.

               

              Thanks again,

              Jonathan

              • 20. Re: Errai JPA Failing To Compile
                Jonathan Fuerth Master

                Okay, inheritance support is implemented now. It should be available in 3.0-SNAPSHOT within 4-6 hours. Please give it a try and let us know if it works for you.

                1 2 Previous Next