-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Mapping Objects
PostPosted: Tue Jan 08, 2013 3:47 pm 
Newbie

Joined: Tue Jan 08, 2013 3:45 pm
Posts: 1
Hello Guys..

I want to map this SQL in my objects (Users, Authorities):

Code:
    CREATE TABLE users 
    ( 
      username character varying(50) NOT NULL, 
      "password" character varying(50) NOT NULL, 
      enabled boolean NOT NULL, 
      CONSTRAINT users_pkey PRIMARY KEY (username) 
    ); 
     
    CREATE TABLE authorities 
    ( 
      username character varying(50) NOT NULL, 
      authority character varying(50) NOT NULL, 
      CONSTRAINT fk_authorities_users FOREIGN KEY (username) 
          REFERENCES users (username) MATCH SIMPLE 
          ON UPDATE NO ACTION ON DELETE NO ACTION 
     
    ); 
     
    CREATE UNIQUE INDEX ix_auth_username 
      ON authorities 
      USING btree 
      (username, authority); 




Actualy, i have 2 classes, like this:

Code:
    @Entity 
    @Table(name = "Users") 
    public class Users{ 
     
        @Id 
        @Column(name = "username", nullable = false, unique = true) 
        private String username; 
     
        @Column(name = "password", nullable = false) 
        private String password; 
     
        @Column(name = "enabled", nullable = false) 
        boolean enabled; 
     
        public String getUsername() { 
            return username; 
        } 
     
        public void setUsername(String username) { 
            this.username = username; 
        } 
     
        public String getPassword() { 
            return password; 
        } 
     
        public void setPassword(String password) { 
            this.password = password; 
        } 
     
        public boolean isEnabled() { 
            return enabled; 
        } 
     
        public void setEnabled(boolean enabled) { 
            this.enabled = enabled; 
     
        }     
    } 

And

Code:
@Entity 
    @Embeddable 
    @Table(name = "Authorities") 
    public class Authorities { 
     
        @Id @OneToOne 
        @JoinColumn(name = "username") 
        private Users username; 
     
        @Column(name = "authority") 
        private String authority; 
     
        public Users getUsername() { 
          return username;   
        }   
        public void setUsername(Users username) {     
            this.username = username;     
        }     
        public String getAuthority() {     
            return authority;   
        }     
      public void setAuthority(String authority) {   
            this.authority = authority; 
        }   
    } 

SO, how can i produce the same with hibernate?

Regards


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.