Hi,

My appfuse version is 2.0-M5.
I have a model class named Service which is mapped to 'services' table. This
model has a <map> type property called 
attributes<key, value> which is realized via one-to-many join table named
service_attributes.

2 questions:

1- Is my mapping correct? Not sure because I can't nominate the second
column (atrr_value) in the join table via the mappings.
2- My service table and its sample data is preserved, but my
service_attributes table is truncated every time I run
'mvn test' and I lose the data in it.
(I know that it's not dropped and recreated because the app has no clue of
the column name of attr_value.)
How can I avoid this?

I did the mapping which can be seen from the enclosed Service.java and the
two ddls for the tables.


@Entity
@Table(name="services")
public class Service {
        
    private Long id;
    
    private String name;
        
        private Map<String, String> attributes = new HashMap<String, String>();
        
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        public Long getId() {
                return id;
        }
        public void setId(Long id) {
                this.id = id;
        }
        
        @Column(nullable = false)
        public String getName() {
                return name;
        }
        public void setName(String name) {
                this.name = name;
        }

        @org.hibernate.annotations.CollectionOfElements
        @JoinTable(
                name = "service_attributes",
                joinColumns = @JoinColumn(name = "id")
        )
        @org.hibernate.annotations.MapKey(
                        columns = [EMAIL PROTECTED](name="attr_key"),
                        }
        )
        @Column(name="attr_value")
        public Map<String, String> getAttributes() {
                return attributes;
        }
        public void setAttributes(Map<String, String> attributes) {
                this.attributes = attributes;
        }
 }

-- ----------------------------
--  Table structure for `services`
-- ----------------------------
CREATE TABLE `services` (
  `id` bigint(20) NOT NULL default '0',
  `name` varchar(255) default NULL,
  PRIMARY KEY  (`id`)
);

-- ----------------------------
--  Table structure for `service_attributes`
-- ----------------------------
CREATE TABLE `service_attributes` (
  `id` bigint(20) NOT NULL default '0',
  `attr_key` varchar(255) NOT NULL default '',
  `att_value` varchar(255) default NULL,
  PRIMARY KEY  (`id`,`attr_key`),
  KEY `FK416A6521F3E5C68F` (`id`),
  CONSTRAINT `FK416A6521F3E5C68F` FOREIGN KEY (`id`) REFERENCES `services`
(`id`)
);
-- 
View this message in context: 
http://www.nabble.com/jpa%3A-value-type-%3Cmap%3E-mapping-tf3558875s2369.html#a9937982
Sent from the AppFuse - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to